Under construction

Still being built. Things may change

Zombie Smash (Small)

Time limit5sMemory limit512 MB

Summary
Plan a route from (0, 0) that smashes the most zombies, each catchable for 1000 ms after it appears, with 8-direction moves and a 750 ms smasher recharge.
Level

Medium5 of 10

Topics
Brute force, Intervals, Geometry
Solved
No attempts yet

Problem

Zombie Smash is a game where you smash zombies with your Zombie Smasher as they pop out of graves in a graveyard. The graveyard is a flat 2D grid. Each zombie pops out of a grave at some cell (X,Y)(X, Y), stands in place for 1000 milliseconds, then drops back into the grave. At most one zombie stands at a grave at a time.

You move to any one of the 8 cells adjacent to your own in 100 milliseconds, so you can step north, east, south, west, northwest, northeast, southwest, or southeast. You may walk through or stand on a cell that a zombie occupies. You smash a zombie the instant you reach the cell it stands on, but after a smash the Zombie Smasher takes 750 milliseconds to recharge, and during that time you cannot smash the next zombie. You are free to keep moving while it recharges. For example, right after smashing a zombie at (0,0)(0, 0):

  • reaching and smashing a zombie at (1,1)(1, 1) takes 750 milliseconds,
  • reaching and smashing a zombie at (20,20)(20, 20) takes 2000 milliseconds.

At time t=0t = 0, when the game starts, you stand at cell (0,0)(0, 0) with a fully charged smasher. After a level ends, work out how many zombies you could have smashed with optimal play.

Input

The first line contains a single integer TT, the number of test cases. Each test case starts with a line containing a single integer ZZ, the number of zombies in the level.

The next ZZ lines each contain three space-separated integers XiX_i, YiY_i and MiM_i, giving the location and the time at which one zombie appears.

  • XiX_i is the XX coordinate of the cell where zombie ii appears.
  • YiY_i is the YY coordinate of the cell where zombie ii appears.
  • MiM_i is the time at which zombie ii appears, in milliseconds after the start of the game. The interval in which a zombie can be smashed is inclusive: if you reach its cell at any time in [Mi,Mi+1000][M_i, M_i + 1000] with a charged Zombie Smasher, you smash that zombie.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤Z≤81 \le Z \le 8
  • −1000≤Xi,Yi≤1000-1000 \le X_i, Y_i \le 1000
  • 0≤Mi≤1080 \le M_i \le 10^8
  • Two zombies are never in the same location at the same time. If one zombie appears at (x,y)(x, y) at time tt, then any other zombie appearing at (x,y)(x, y) appears at or before t−1001t - 1001, or at or after t+1001t + 1001.

Output

For each test case, print one line in the form Case #c: d, where cc is the test case number starting from 1 and dd is the largest number of zombies you could have smashed in that level.

Examples2

  1. Example 1

    Input
    3
    4
    1 0 0
    -1 0 0
    10 10 1000
    10 -10 1000
    3
    1 1 0
    2 2 0
    3 3 0
    5
    10 10 1000
    -10 10 1000
    10 -10 1000
    -10 -10 1000
    20 20 2000
    
    Expected output
    Case #1: 3
    Case #2: 2
    Case #3: 2
    
  2. Example 2

    Input
    2
    1
    0 0 0
    1
    1000 1000 0
    
    Expected output
    Case #1: 1
    Case #2: 0