x
InterviewTime limit1sMemory limit1024 MB
Given a vertical cylinder and aircraft flying straight lines with descent, find the times each aircraft enters and exits the cylinder, if it does.
Problem
A friend of yours is a paraglider pilot who flies at Tiger Mountain outside of Seattle, WA. The site is popular and, unfortunately, also in the landing approach patterns of some flights heading to Sea-Tac airport or Boeing field. This could lead to dangerous situations involving high-flying paragliders and low-flying jets. Your friend, knowing you are a code guru, has asked for your help in developing an early warning system that tells paraglider pilots when jet traffic might intrude upon their airspace.
You found a web API that gives real-time flight data on nearby air traffic, and another web API that sends text messages to pilots. Now you need to work out which flights could cause a problem.
Treat the airspace as a 3D coordinate space measured in feet. This is reasonable because, for small distances, latitude and longitude can be treated as coordinates on a plane. The paragliders stay inside a 3D cylinder with a center, a radius, and lower and upper altitude bounds. Flight data contains each aircraft's position, altitude, heading, speed, and descent rate. Heading is in degrees, where 0 degrees is along the positive x axis and 90 degrees is along the positive y axis. Airspeed is in feet per second, along vector in the diagram, and descent is along vector .

If an aircraft's flight path intersects the bounded cylinder, compute the entry and exit times in seconds from the current time, and output a message with those times. Otherwise, output a message to ignore the aircraft.
Input
The first line describes the airspace and contains five floating point numbers: the coordinates of the cylinder's center in feet (), the radius in feet (), and the lower bound and upper bound in feet ().
The second line contains a single integer (), the number of aircraft to process.
The next lines each describe one incoming aircraft with seven numbers: an integer flight number (), the position of the aircraft (), the heading in degrees (), the altitude in feet (), the speed in feet per second (), and the descent rate in feet per second (). Every value except the flight number is a floating point number.
Assume that no aircraft starts inside the cylinder. Also assume that if an aircraft enters the cylinder, it is inside the cylinder at more than one point.
Output
If the aircraft does not enter the cylinder, print the following message, where is the flight number:
Flight f is safe.
If the aircraft intersects the cylinder, print the following message, where is the flight number, is the time in seconds when the aircraft enters the cylinder, and is the time in seconds when it exits:
Incoming! Flight f enters at t0 and exits at t1.
Round both times to two decimal places. For example, 0.274 is printed as 0.27, and 0.275 is printed as 0.28. If the aircraft grazes the cylinder (within an error of ), treat it as having entered and exited.