Untitled
unknown
plain_text
2 years ago
2.9 kB
3
Indexable
Pipe Network Có tổng cộng 7 loại ống, được đánh số từ 1-7 như hình bên dưới: Chỉ các đường ống được kết nối mới có thể cho phép nhiên liệu đi qua chúng. Hai ống được kết nối nếu chúng có một điểm cuối chung. Ví dụ : - Trong trường hợp này, nhiên liệu có thể chảy từ A sang B - Nhưng trường hợp này nhiên liệu không thể chảy từ A sang B (Ống ở A không có điểm cuối chung với ống ở B) Tuy nhiên, máy bơm được sử dụng để phân phối nhiên liệu có giới hạn về hiệu suất của nó. Tùy thuộc vào loại của nó, máy bơm chỉ có thể bơm nhiên liệu đến giới hạn của nó. Ví dụ, giả sử giới hạn của bơm là 3, nghĩa là từ vị trí xuất phát, nhiên liệu chỉ có thể chảy đến vị trí xa nhất cách đó 3 bước (bao gồm cả điểm xuất phát). Given the map of pipe network, the location of the fuel tank (start position), the limit of pump, write a program to calculate the total number of pipes that fuel can flow to. Example 1: In this case, the height of the map (N) is 5, the length of of the map (M) is 6, location of the fuel tank is (2,1), the limit of the pump is 3 - First fuel is pumped to location (2,1) - Second, fuel flows to location (2,0) and (2,2) - Third, fuel flows to location (1,2) and (2,3) As the limit of pump is reached, the fuel can not flow any further. Hence, the total number of pipes that fuel can flow to is 5. Example 2: In this case, the height of the map (N) is 5, the length of of the map (M) is 6, location of the fuel tank is (2,2), the limit of the pump is 6. The answer is 15. [Constraints] - The fuel tank is alway placed at a location where a pipe exist [Input] - The number of test case T (T <= 50) - In each TC, the first row will give : + The size of the map N x M (5 <= N, M <= 50) + The location of fuel tank (start position) (0-based index) + The limit of the pump P (1 <= P <= 20) - Detail of the map will be given at next N rows, the value C of each cell represent the pipes (total 7 kind of pipes, 0 <= C <= 7), value 0 mean there is no pipe at that location. 5 => Total 5 test cases 5 6 2 1 3 => The size of the map is 5 x 6, starting point is (2,1), the limit of pump is 3 0 0 5 3 6 0 => The first row of the map 0 0 2 0 2 0 => The second row of the map 3 3 1 3 7 0 0 0 0 0 0 0 0 0 0 0 0 0 5 6 2 2 6 3 0 0 0 0 3 2 0 0 0 0 6 1 3 1 1 3 1 2 0 2 0 0 2 0 0 4 3 1 1 10 10 4 3 9 0 0 0 0 0 0 0 0 0 0 0 0 0 7 5 0 5 0 0 0 0 0 3 2 2 6 0 0 0 0 0 4 7 2 2 2 7 0 0 4 0 3 0 1 1 2 2 0 0 5 0 5 6 1 1 1 1 6 2 5 7 4 1 2 0 0 4 6 0 0 5 3 1 7 0 2 2 6 5 7 7 3 2 1 1 7 1 0 2 7 3 4 0 0 4 0 5 1 0 1 ... [Output] - The total number of pipes that fuel can flow to Case #1 5 Case #2 15 Case #3 29
Editor is loading...