Destroy Them With Lazers Introduction

The arena is a flatland dotted with skyscrapers, which your enemies use for cover. You and your enemies shoot each other with lasers. All of you carry jet packs, allowing flight.

Which enemies can you hit with your laser, and which are hiding?

Problem

First, the size of an arena is given by an integer n on a single line. The following n lines contain n integers per line separated by a space. Each integer represents the height of the building at that location. Each building is a rectangular solid, 1 unit by 1 unit by height units.

Next, your location is given on a single line as three floating point numbers x, y, z.

Finally, the number of enemies are given by an integer m on a single line. The following m lines contain three floating point numbers per line separated by a space. These represent the  x, y, and z coordinates of an enemy. The coordinate system is defined as follows:


x is measured from left to right in the city input
y is measured from top to bottom
z is measured from the ground up


For each enemy, if an unobstructed line can be drawn from you to that enemy, output a positive integer. Otherwise, output a negative integer. Separate outputs with a new line.

Sample Input

Comments, denoted by '#', are present to help you quickly see what each line does. They will not be present in the actual input.

5              # Size of the map
0 0 0 0 0      # Buildings
0 0 0 0 0      # Buildings
4 4 4 4 4      # Buildings
0 0 0 0 0      # Buildings
0 0 0 0 0      # Buildings
2.5 0.0 4.0    # Your location
3              # Number of enemies
2.5 5.0 0.1    # Enemy location
2.5 5.0 5.0    # Enemy location
0.0 2.7 4.5    # Enemy location


Sample output

For the sample input above, we output the following:

-1
1
1


Assumptions


0 &lt; n &lt; 100
0 &lt; m &lt; 100
0 &lt;= x &lt;= n
0 &lt;= y &lt;= n
0 &lt;= z &lt; n
Players will not be located on or inside of a corner, edge, or side of a building
Your line of sight to an enemy will never be tangent to the corner, edge, or side of a building
A player is not an obstruction
Perl, 301 296 282

Edit 2: Actually, competition or not, there is no reason not to golf it a little further. Test it online.

Edit: Couple of parentheses gone, simpler regex to check for non-zero integer. 

With newlines and indentation for readability:

sub i{&lt;&gt;=~/\S+/g}
@b=map[i],@r=0..&lt;&gt;-1;
print.1&lt;=&gt;(map{
    @a[1,0,2,4,3]=@a;
    @b=map{$i=$_;[map$b[$_][$i],@r]}@r;
    grep$a[3]
        &amp;&amp;($k=(($x=$_)-$a[0])/$a[3])**2&lt;=$k
        &amp;&amp;pop[sort map@{$b[$_]}[$x-!!$x,$x],
                   ($_=$a[1]+$k*$a[4]),$_-/^\d+$/]
           &gt;=$a[2]+$k*$a[5]
    ,@R=@r
}@a=map$_-shift@v,i,@u=@v=@$_),$/for([i])x&lt;&gt;


It requires 5.14 because of scalar (array reference) argument to pop.