Connection Status:
Competition Arena > FlightDataRecorder
SRM 721 · 2017-08-30 · by cgy4ever · Simulation
Class Name: FlightDataRecorder
Return Type: double
Method Name: getDistance
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

A Flight Data Recorder is a device that records lots of parameters during a flight. In this task you are going to use some of those parameters to calculate the distance between the start point and the end point of the flight.

The whole flight consists of one or more segments. During each segment the plane was heading in a fixed direction. For each segment, you are given the direction and the distance traveled. More precisely, you are given two int[]s: heading and distance. For each valid i: during segment i of the flight the plane traveled in the direction heading[i] and the distance it traveled was distance[i]. The heading is an angle in degrees between North and the direction of flight, measured in clockwise direction. For example, 0 means North, 90 means East, 180 means South, and 270 means West.

Assume that the airplane is a point moving in a two-dimensional plane. Also, assume that between the segments the airplane can change its heading in an instant.

Calculate and return the distance between the start and the end of the flight.

Notes

  • Your answer will be considered correct if its absolute or relative error does not exceed 10^(-9).

Constraints

  • heading will contain between 1 and 50 elements, inclusive.
  • heading and distance will contain the same number of elements.
  • Each element in heading will be between 0 and 359, inclusive.
  • Each element in distance will be between 1 and 1,000, inclusive.
Examples
0)
{90,0}
{3,4}
Returns: 5.0

The airplane flew 3 units of distance towards the East and then 4 units of distance towards the North. From the Pythagorean theorem we know that the distance between the start and the end of the flight is sqrt(3*3 + 4*4) = 5.

1)
{37,37,37,37}
{1,10,100,1000}
Returns: 1111.0

The heading never changed, so the answer is 1+10+100+1000.

2)
{0,120,240,0,120,240}
{999,999,999,999,999,999}
Returns: 6.431098710768743E-13

The airplane returned back to the start point.

3)
{76,321,214,132,0,359,74,65,213}
{621,235,698,1,35,658,154,426,965}
Returns: 153.54881555325184
4)
{0}
{1}
Returns: 1.0

Submissions are judged against all 83 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FlightDataRecorder with a public method double getDistance(vector<int> heading, vector<int> distance) · 83 test cases · 2 s / 256 MB per case

Submitting as anonymous