Whac-a-Mole
Time limit1sMemory limit128 MB
Given each mole's position and time, find the maximum number of moles whacked while the hammer moves at most distance d between time steps.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Geometry, Bit manipulation
- Solved
- No attempts yet
Problem
While visiting a traveling fun fair you suddenly get the urge to beat the high score in the Whac-a-Mole game. The goal of Whac-a-Mole is to whack moles with a hammer. To make the job easier you have first consulted a fortune teller, and now you know the exact pattern in which the moles will appear.
The moles come out of holes located at the integer points satisfying in a two-dimensional coordinate system. At each time step some moles appear and then disappear again before the next time step. After the moles appear but before they disappear, you may move your hammer in a straight line to any point that is at Euclidean distance at most from its current position . The hammer may only be moved to points with integer coordinates. A mole is whacked if the center of the hole it came out of lies on the segment between and (both endpoints included). Each whacked mole earns you one point. Before the first time step, you may place your hammer at any position you like.
Input
The input consists of several test cases. Each test case starts with a line containing three integers , and , where and are as described above and is the total number of moles that will appear (, , and ). Then follow lines, each containing three integers , and giving the position and time of the appearance of a mole ( and ). No two moles will appear at the same place at the same time.
The input ends with a test case where ; this case must not be processed.
Output
For each test case, output a single line containing one integer: the maximum score you can achieve.