Jetpack Sniper 3000 Fragfest Extreme

Time limit1sMemory limit128 MB

Summary
For each of several 10x10 height grids and four 3D points, decide whether a building blocks the segment from you to players A, B, and C.
Level

Hard8 of 10

Topics
Geometry, Implementation, Brute force
Solved
No attempts yet

Problem

You are a beta tester for a new online game, Jetpack Sniper 3000 Fragfest Extreme. Players wearing jetpacks fly over a metropolitan area and try to shoot one another with laser guns. The only cover is the city's ever-present glass skyscrapers.

To help you play, you have written a program that reports which players you can currently shoot (or be shot by): the players who have an unobstructed straight-line view of your position.

Input

The first line contains a single integer nn, the number of cities.

Each city is a 10×1010 \times 10 grid of city blocks. Every block holds one skyscraper whose integer height ranges from 00 to 99. A city is given as 1010 lines of 1010 digits; the digit in row yy (from the top, 00-indexed) and column xx (from the left, 00-indexed) is the height of the skyscraper occupying that block.

After the grid comes one line with four coordinate triples. The first is your position; the next three are the positions of players A, B, and C. Each position is written as (x, y, height), where xx increases from left to right, yy increases from top to bottom, and height is measured upward from the ground. The point (0,0,0)(0, 0, 0) is the top-left corner of the grid at ground level.

Notes:

  • Coordinates may be floating-point numbers.
  • No player (including you) is ever inside a building or on its surface, edges, or corners. No line of sight is tangent to a face, edge, or corner of a building in a way that would change the answer.

Output

For each city, print the header Fragfest City #X, where X is the city's number (11 for the first city, 22 for the second, and so on). Then print one line for each of players A, B, and C, in that order: print Player Y is in sight if no building blocks your straight-line view of that player, or Player Y is hiding if a building obstructs it (Y is the player's letter).

Assume the following simplifications:

  1. Each skyscraper is a rectangular box of size 1×1×height1 \times 1 \times \text{height}.
  2. Each player is a single point.
  3. A player never blocks the view of another player.

Examples1

  1. Example 1

    Input
    2
    0000005000
    0000005000
    0000005000
    0000005000
    9999999999
    0000000000
    0000000000
    0000000000
    0000000000
    0000000000
    (0,0,0) (10, 10, 10) (5.5, 5.5, 5.5) (9, 1.0, 9)
    0123456789
    1000000000
    2064646400
    3045555600
    4065005400
    5045005600
    6065555400
    7046464600
    8000000000
    9123456789
    (4.5, 4.5, 5.5) (7.5, 4.5, 5.5) (1.5, 4.5, 5.1) (7.5, 4.5, 6.5)
    
    Expected output
    Fragfest City #1
    Player A is hiding
    Player B is hiding
    Player C is in sight
    Fragfest City #2
    Player A is in sight
    Player B is hiding
    Player C is in sight