Mummy Madness
Time limit6sMemory limit128 MB
Given mummy start positions on an infinite grid, compute how many time steps a fleeing player survives when both sides move on a king-step grid.
- Level
Hard9 of 10
- Topics
- Binary search, Geometry, Math, Game theory
- Solved
- No attempts yet
Problem
On an expedition across the desert you open an ancient Egyptian tomb, and the instant the door swings open the empty sand around you erupts with grumpy mummies. Your only hope is to run and stay ahead of them for as long as possible. Assuming neither you nor the mummies ever tire, how many time steps pass before a mummy finally catches you?
Model the desert as an infinite grid of squares. You and the mummies take turns, and you move first. On your turn you may move to any of the eight squares adjacent to your current square, or stay where you are. On the mummies' turn, each mummy independently moves to the one adjacent square (among its eight neighbours) that minimizes its Euclidean distance to you — equivalently, every mummy shrinks the gap by one along each axis on which it is not already aligned with you. Two mummies may occupy the same square.
A time step consists of your move followed by every mummy's move. A mummy catches you if it moves onto the square you occupy, or if you move onto a square occupied by a mummy. You play to survive as long as possible.
After how many time steps are you caught?
For instance, suppose four mummies start at , , and while you start at the origin. However you move, after four time steps the mummy that began at reaches you, so the answer is .
Input
The input consists of several test cases. Each test case begins with an integer (), the number of mummies. Each of the next lines contains two integers and (, ), the starting square of one mummy. Your own starting square is , and no mummy starts there.
The last test case is followed by a line containing a single .
Output
For each test case, print a line Case k: r, where is the test case number (starting from ) and is the maximum number of time steps you survive before being caught (that is, the total number of turns you get to take), or the word never if you can avoid capture forever.
Hint
Relax — after working this out you wake up safe in a hotel room. The furious mummies were only a dream. Or were they?