Under construction

Still being built. Things may change

x

Interview

Time limit1sMemory limit1024 MB

Summary
Given a vertical cylinder and aircraft flying straight lines with descent, find the times each aircraft enters and exits the cylinder, if it does.
Level

Medium5 of 10

Topics
Geometry, Math
Solved
No attempts yet

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 ss in the diagram, and descent is along vector dd.

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 (xc,yc)(x_c, y_c) of the cylinder's center in feet (−50000≤xc,yc≤50000-50000 \le x_c, y_c \le 50000), the radius rr in feet (1≤r≤100001 \le r \le 10000), and the lower bound ll and upper bound uu in feet (0≤l<u≤100000 \le l < u \le 10000).

The second line contains a single integer nn (1≤n≤1001 \le n \le 100), the number of aircraft to process.

The next nn lines each describe one incoming aircraft with seven numbers: an integer flight number ff (1000≤f≤99991000 \le f \le 9999), the position (xa,ya)(x_a, y_a) of the aircraft (−200000≤xa,ya≤200000-200000 \le x_a, y_a \le 200000), the heading hh in degrees (0≤h<3600 \le h < 360), the altitude aa in feet (1000≤a≤350001000 \le a \le 35000), the speed ss in feet per second (100≤s≤10000100 \le s \le 10000), and the descent rate dd in feet per second (0≤d≤s0 \le d \le s). 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 ff is the flight number:

Flight f is safe.

If the aircraft intersects the cylinder, print the following message, where ff is the flight number, t0t_0 is the time in seconds when the aircraft enters the cylinder, and t1t_1 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 10−610^{-6}), treat it as having entered and exited.

Examples2

  1. Example 1

    Input
    0.0 0.0 1000.0 0.0 10000.0
    2
    1200 -5000.0 0.0 0.0 7500.0 5000.0 500.0
    2400 -5000.0 0.0 90.0 7500.0 5000.0 500.0
    
    Expected output
    Incoming! Flight 1200 enters at 0.80 and exits at 1.21.
    Flight 2400 is safe.
    
  2. Example 2

    Input
    -1000.0 1000.0 2000.0 1000.0 10000.0
    1
    1000 -6000.0 1000.0 0.0 12000.0 4472.0 2000.0
    
    Expected output
    Incoming! Flight 1000 enters at 1.00 and exits at 1.75.