21
2
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:
xis measured from left to right in the city inputyis measured from top to bottomzis 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 <
n< 100 - 0 <
m< 100 - 0 <=
x<=n - 0 <=
y<=n - 0 <=
z<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
This question appears to have a cumbersome IO format. Can you fix it/can I just take in a 2D array of numbers? – Nissa – 2017-11-27T13:07:16.210
@StephenLeppik Sorry, that wouldn't be fair to those that already posted their answers under the current spec. – Rainbolt – 2017-11-27T14:30:24.957
@StephenLeppik I hope that the downvote was based on the challenge as a whole, and not just the input format. When I posted this challenge three years ago, there was no guidance on what input formats made everyone happy, and so I created my own. In fact, I was one of the first ones to ask the community for their preferences. If I were to repost today, I would absolutely allow a more flexible input. Making input easier would affect the competitiveness of existing answers, so I'm not changing it.
– Rainbolt – 2017-11-27T18:44:28.990Glad to see it out of the sandbox :) – Timtech – 2014-05-21T14:04:38.613
7If I can't destroy an enemy, may I join them? – John Dvorak – 2014-05-21T14:13:24.037
@user80551 Sorry, I had to roll back your edit to the title because the mispelling was intentional. Google it. – Rainbolt – 2014-05-22T13:42:36.847
@Rusher Oh , sorry, IDK that – user80551 – 2014-05-22T15:22:42.740
Such a good question. Maybe not perfect for golfing but really good. – WorldSEnder – 2014-05-22T20:21:47.567
4
Related: https://www.youtube.com/watch?v=NKTpWi5itOM
– qwr – 2014-05-22T21:39:37.973