Topcoder SRM 721 Div.2 A. FlightDataRecorder
来源:互联网 发布:淘宝原价和现价步骤 编辑:程序博客网 时间:2024/06/16 09:57
这场是我第一次打Topcoder,之前顶多只是写写前面的SRM的题。这一场在晚上11:00。我T3被题意杀了30分钟!!!结果打完之后连system test都测完了…尴尬。最后在practice room里交上去跑了下system test,我是A的……感觉错过了100个亿.jpg结果我T2还fst了..目前rating:1385(蓝名)。
A. FlightDataRecorder
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 vector 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.
Definition
Class:
FlightDataRecorder
Method:
getDistance
Parameters:
vector , vector
Returns:
double
Method signature:
double getDistance(vector heading, vector distance)
(be sure your method is public)
Limits
Time limit (s):
2.000
Memory limit (MB):
256
Stack limit (MB):
256
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(3∗3+4∗4)−−−−−−−−−−−√=5 .
1)
{37,37,37,37}
{1,10,100,1000}
Returns: 1111.0
The heading never changed, so the answer is1+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
题意
有一架飞机,给你一堆角度和一堆相对应的长度,表示飞机在第i个时刻朝向第i个角度飞行了第i个长度。0度表示朝北,90度表示朝东,180度表示朝南,270度表示朝西,问你当所有路线飞完后,问你该飞机到原点距离是多少。
思路
这题是最简单的一题,你只要善用cmath库里的sin和cos就行了,只是要注意,cmath里的sin和cos是要用弧度角表示的。所以我们需要先将角度化为弧度再去做就行了。还有,在这里sin对应的是x坐标,cos对应的是y坐标。
Code:
#include<bits/stdc++.h> typedef long long ll;using namespace std;const double pi=acos(-1);class FlightDataRecorder {public: double getDistance( vector <int> heading, vector <int> distance ) { double posx=0.0,posy=0.0; for(int i=0;i<heading.size();i++) { posy=posy+cos(heading[i]*pi/180.0)*(double)distance[i]; posx=posx+sin(heading[i]*pi/180.0)*(double)distance[i]; } return sqrt(posx*posx+posy*posy); }};
- Topcoder SRM 721 Div.2 A. FlightDataRecorder
- Topcoder SRM 721 Div.2 B. RememberWordsEasy
- Topcoder SRM 721 Div.2 C. ApocalypseEasy
- Topcoder SRM 462 DIV 2
- topcoder srm 518 div 2
- TopCoder SRM 561 Div 2
- Topcoder SRM 565 Div.2
- Topcoder SRM 628 DIV 2
- TopCoder SRM 144 DIV 2
- TopCoder——SRM 516 DIV 2
- TopCoder——SRM 518 DIV 2
- TopCoder——SRM 519 DIV 2
- Topcoder SRM 505 Div 2 hard
- TopCoder——SRM 520 DIV 2
- TopCoder——SRM 521 DIV 2
- topcoder SRM div 2 level 1
- TopCoder SRM 634 Div.2[ABC]
- TopCoder SRM 633 Div.2 500 Jumping
- kaggle 入门
- SSH无密码登录
- php2python
- 8.leetCode627: Swap Salary
- 用jquery动画隐藏显示文本框
- Topcoder SRM 721 Div.2 A. FlightDataRecorder
- Android 在代码中安装 APK 文件
- ffmpeg滤镜专题2-高斯模糊
- Android 编码规范
- 20170928 使用网页管理集群 按行读取写入useragent txt文件
- script到底应该放在哪里
- CURL访问远程方法
- Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
- 屏幕适配基础