#P2963. [USACO09NOV] Cow Rescue G
[USACO09NOV] Cow Rescue G
Description
Bessie is trapped in a triangular maze with rows (). For example, a maze with rows is shown below.
The -th row of the maze contains triangles. Numbering from the left, the triangles are named , , and so on.
Bessie can move to any triangles that share an edge with her current triangle (often three neighbors). For example, if she is at , she can move to , , and . Each move to a neighboring triangle takes one minute.
Farmer John has learned that Bessie is trapped and, by tracking her iPhone, knows she starts at triangle . His love for Bessie knows no bounds, so he wants her back in the minimum possible time.
There are exits () located at various triangles in the maze. Entering any exit triangle allows Bessie to escape, and it takes one additional minute after entering an exit triangle to leave the maze.
Find the minimum time in minutes, , required for Bessie to exit the maze, and report the exit she uses, . If more than one exit requires only minutes, output the one with the smallest row. If there is still a tie, output the one with the smaller column.
Input Format
- Line 1: Two space-separated integers: and .
- Line 2: Two space-separated integers: and .
- Lines : Line contains two space-separated integers giving the location of exit : and .
Output Format
- Line 1: Two space-separated integers: and .
- Line 2: A single integer: .
4 2
2 1
3 5
4 4
4 4
4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号