This Too Shall Pass
Time limit3sMemory limit256 MB
Find every teammate joined to player 1 by a straight segment that touches no guarded square.
- Level
Medium4 of 10
- Topics
- Geometry, Brute force
- Solved
- No attempts yet
Problem
A soccer field is drawn as a grid with rows and columns. Every player takes up one grid square, and the offensive players and the defensive players all stand on different squares. The offensive players are numbered from 1 in the order they appear in the input, and player 1 has the ball.
A defender can step to a neighboring square to intercept a pass, so one defender guards the square he stands on plus the eight squares that meet it along a side or at a corner, nine squares in all. Squares that fall outside the grid are not counted. Guarded areas of different defenders may overlap.
Player is open when the segment that joins the center of player 1's square to the center of player 's square touches no guarded square at any point. Grazing a single corner point of a guarded square is enough for the pass to be intercepted. If a defender guards player 1's own square or the receiver's square, an endpoint of the segment already lies inside a guarded square, so that pass is not open. Offensive players never block a pass to another offensive player.
Find every offensive player that player 1 can pass to.
Input
The input holds several test cases.
The first line of each test case holds four integers , , , separated by spaces: the number of rows, the number of columns, the number of offensive players, and the number of defensive players. (, , , , )
The next lines each hold the row and the column of one offensive player. Rows and columns are numbered from 0, so a row number is less than and a column number is less than . The next lines hold the defenders in the same format. No two players stand on the same square.
The offensive players are numbered from 1 in the order given, and player 1 has the ball.
A line reading 0 0 0 0 ends the input. That line is not a test case.
Output
For each test case, print Case x: on one line, then the numbers of the offensive players that player 1 can pass to, in increasing order. Put one space in front of each number. is the test case number counted from 1.
If no player is open, print Case x: with nothing after it.