Aircraft
SRM 347 · 2007-05-01 · by StevieT
Problem Statement
You will be given the threshold distance R and the positions and velocities of the aircraft in 4
Notes
- The distance between two points (x1, y1, z1) and (x2, y2, z2) is given by sqrt((x1-x2)2 + (y1-y2)2 + (z1-z2)2).
Constraints
- p1, v1, p2 and v2 will contain exactly 3 elements.
- Each element of p1, v1, p2 and v2 will be between -10000 and 10000, inclusive.
- R will be between 0 and 10000, inclusive.
{15,50,5}
{25,1,0}
{161,102,9}
{-10,-10,-1}
10
Returns: "YES"
At time 4, the first aircraft will be at position {115,54,5} and the second at {121,62,5}, which is the first point in time at which they are exactly 10 distance units apart.
{0,0,0}
{2,2,0}
{9,0,5}
{-2,2,0}
5
Returns: "YES"
At time 2.25, aircraft 1 will be at {4.5, 4.5, 0} and aircraft 2 at {4.5, 4.5, 5}, exactly a distance of 5 units apart.
{0,0,0}
{-2,2,0}
{9,0,5}
{2,2,0}
5
Returns: "NO"
The aircraft are flying away from each other here, so the distance always increases with time.
{-4921,250,5852}
{-2,1,-2}
{-2,-1729,-9307}
{-2,0,0}
9864
Returns: "YES"
{-6987,-881,-5232}
{0,-2,-2}
{9835,-872,8837}
{-1,-2,-4}
8755
Returns: "YES"
{-2838,-7940,-2936}
{1,1,-2}
{532,3850,9590}
{1,0,-3}
3410
Returns: "YES"
The closest approach of the aircraft occurs at time 12,158
{-8509,9560,345}
{-89,-33,62}
{-5185,-1417,2846}
{-58,24,26}
8344
Returns: "YES"
A near miss occurs between times 111 and 112
{-7163,-371,-2459}
{-59,-41,-14}
{-2398,-426,-5487}
{-43,27,67}
5410
Returns: "NO"
The aircraft almost have a near miss between times 15 and 16, but stay just outside the threshold distance.
{1774,-4491,7810}
{-12,19,-24}
{2322,3793,9897}
{-12,19,-24}
10000
Returns: "YES"
The aircraft are here flying with identical velocities, so the distance between them never changes. The distance at time 0 is lower than the threshold, so a near miss is already underway.
Submissions are judged against all 166 archived test cases, of which 9 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Aircraft with a public method string nearMiss(vector<int> p1, vector<int> v1, vector<int> p2, vector<int> v2, int R) · 166 test cases · 2 s / 256 MB per case