eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Knight Match Play

Knight Match Play

There are two knight teams, they have \textbf{N} and \textbf{M} knights respectively. The knights are numbered from \textbf{1} to \textbf{N} and \textbf{1} to\textbf{M} in their own team. They are trapped in an \textbf{W*H} grid puzzle. The puzzle only has four exituses which are the four corners of the puzzle. Only the directions up,down,left, right could the knight move to and the time move from one grid to the adjacent is fixed. They can form a "fight partner" if two knights sufficing the following conditions: \includegraphics{https://static.e-olymp.com/content/6e/6e3132f8381f2713c4b110b4e1aec414100c1ac9.jpg} \begin{enumerate} \item The two knights come from different teams. \item Both of them can arrive to one of the exituses. \item The least time need to arrive to one of the exituses is same. \end{enumerate} So how many "fight partners" they can form? For this action, the leader gives the follow directives: \begin{enumerate} \item Each team renumbering the knights with their least time need to use to get out of the puzzle. So the one who use the least time will get the \textbf{ID} \textbf{1} and the one use the most time will get the \textbf{ID} \textbf{N} or \textbf{M}. If some of them use the same time, then whose original \textbf{ID} is lower, who will get a lower \textbf{ID}. \item The chosen knights from the same team should have the continuous \textbf{ID}. \item Form "fight partners" according to the \textbf{ID}s one by one. That is to say the one has the lowest \textbf{ID} should form with the one has the lowest \textbf{ID} in another team, and so on. \end{enumerate} \InputFile There are several test cases.The input of every test case are described as below. First line, there are four integers \textbf{N}, \textbf{M}, \textbf{W}, \textbf{H}. (\textbf{0} < \textbf{N}, \textbf{M} < \textbf{300}, \textbf{10} < \textbf{W}, \textbf{H} < \textbf{50}). Then there are \textbf{H} lines, each line with \textbf{W} characters indicate for the puzzle.A character of '\textbf{.}' indicate the grid is empty, every empty grid could contain infinitely of knights. A character of '\textbf{#}' means the grid has a barrier and none knight can step into it. The four corners are empty. Then there \textbf{N+M} lines, each line with a pair of integers (\textbf{x}, \textbf{y}) (\textbf{0} ≤ \textbf{x} < \textbf{H}, \textbf{0} ≤ \textbf{y} < \textbf{W}) indicate for the knight is in the\textbf{x}^th line and \textbf{y}^th column originally. The input will finish with the end of file. \OutputFile An integer indicate for the maximal number of "fight partner" they can form.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4 3 7 6
.#...#.
..#....
.......
..#....
....##.
.##....
1 3
4 2
2 2
1 5
3 5
4 3
3 0
Выходные данные #1
3
Источник Hunan University 2011 the 7th Programming Contest