PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000095. Larry nhặt hạt dẻ (Nuts for nuts..)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Larry nhặt hạt dẻ (Nuts for nuts..)
Nuts for nuts..
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Larry starts at cell L on a grid, with nuts at # cells. Larry may move to any of eight neighboring cells, and all cells are passable. Find the minimum number of steps needed to collect all nuts and return to L. The distance between cells is .
Input
First , followed by rows containing L, #, .. Let be the number of nuts #.
Output
Print the minimum number of steps.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
2 2
L#
..
Output
2
Explanation
The only nut # is adjacent to L. Under eight-direction movement it takes one step to reach and one to return, totaling .