poj2354——Titanic
来源:互联网 发布:手机淘宝家乡版 编辑:程序博客网 时间:2024/04/27 19:32
Titanic
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2222 Accepted: 559
Description
It is a historical fact that during the legendary voyage of "Titanic" the wireless telegraph machine had delivered 6 warnings about the danger of icebergs. Each of the telegraph messages described the point where an iceberg had been noticed. The first five warnings were transferred to the captain of the ship. The sixth one came late at night and a telegraph operator did not notice that the coordinates mentioned were very close to the current ship's position.
Write a program that will warn the operator about the danger of icebergs!
Write a program that will warn the operator about the danger of icebergs!
Input
The input messages are of the following format:
Here <n> is a positive integer, <HH>:<MM>:<SS> is the time of the message reception, <X1>^<X2>'<X3>" <NL/SL> and <Y1>^<Y2>'<Y3>" <EL/WL> means "X1 degrees X2 minutes X3 seconds of North (South) latitude and Y1 degrees Y2 minutes Y3 seconds of East (West) longitude."
Message #<n>.Received at <HH>:<MM>:<SS>. Current ship's coordinates are <X1>^<X2>'<X3>" <NL/SL> and <Y1>^<Y2>'<Y3>" <EL/WL>.An iceberg was noticed at <A1>^<A2>'<A3>" <NL/SL> and <B1>^<B2>'<B3>" <EL/WL>.===
Here <n> is a positive integer, <HH>:<MM>:<SS> is the time of the message reception, <X1>^<X2>'<X3>" <NL/SL> and <Y1>^<Y2>'<Y3>" <EL/WL> means "X1 degrees X2 minutes X3 seconds of North (South) latitude and Y1 degrees Y2 minutes Y3 seconds of East (West) longitude."
Output
Your program should print to the output file message in the following format:
Where <s> should be the distance between the ship and the iceberg, (that is the length of the shortest path on the sphere between the ship and the iceberg). This distance should be printed up to (and correct to) two decimal digits. If this distance is less than (but not equal to!) 100 miles the program should print one more line with the text:
The distance to the iceberg: <s> miles.
Where <s> should be the distance between the ship and the iceberg, (that is the length of the shortest path on the sphere between the ship and the iceberg). This distance should be printed up to (and correct to) two decimal digits. If this distance is less than (but not equal to!) 100 miles the program should print one more line with the text:
DANGER!
Sample Input
Message #513.Received at 22:30:11. Current ship's coordinates are 41^46'00" NL and 50^14'00" WL.An iceberg was noticed at41^14'11" NL and 51^09'00" WL.===
Sample Output
The distance to the iceberg: 52.04 miles.DANGER!
Hint
For simplicity of calculations assume that the Earth is an ideal sphere with the diameter of 6875 miles completely covered with water. Also you can be sure that lines in the input file break exactly as it is shown in the input samples. The ranges of the ship and the iceberg coordinates are the same as the usual range for geographical coordinates, i.e. from 0 to 90 degrees inclusively for NL/SL and from 0 to 180 degrees inclusively for EL/WL.
这题主要是处理字符串以及球面上的面积公式,最后与100比较时,要考虑浮点数的误差。
球面距离计算公式:d(x1,y1,x2,y2)=r*arccos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y1-y2))
x1,y1是纬度\经度的弧度单位,r为半径
#include<iostream>#include<cstdio>#include<iomanip>#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstdlib>#include<string>#include<cstring>#include<algorithm>#include<map>#include<cctype>#define PI 3.1415927using namespace std;double change(int a,int b,int c)//把度数换种形式{double sum=0;sum+=a;sum+=(b*60.0+c*1.0)/3600.0;return sum;}double cal(double a,double b,double c,double d)//计算距离{double sum;sum=6875.0*acos(cos(a/180.0*PI)*cos(c/180.0*PI)*cos((b-d)/180.0*PI)+sin(a/180.0*PI)*sin(c/180.0*PI));return sum;}int main(){string message;while(getline(cin,message,'=')){string tem;cin>>tem;int num[100],k=0;for(int i=0;i<message.size();i++)//获取所有数{string tem;bool bo=0;while(isdigit(message[i])){tem+=message[i];i++;bo=1;}if(bo){num[k++]=atoi(tem.c_str());//cout<<num[k-1]<<endl;i--;}}int x1,x2,x3,y1,y2,y3,a1,a2,a3,b1,b2,b3;//从第5个数开始是坐标x1=num[4];x2=num[5];x3=num[6];y1=num[7];y2=num[8];y3=num[9];a1=num[10];a2=num[11];a3=num[12];b1=num[13];b2=num[14];b3=num[15];double a,b,c,d;a=change(x1,x2,x3);b=change(y1,y2,y3);c=change(a1,a2,a3);d=change(b1,b2,b3);tem.clear();for(int i=0;i<message.size();i++)//判断坐标的正负{if(message[i]=='"')tem+=message[i+2];}//cout<<tem<<endl;if(tem[0]=='S') a=-a;if(tem[1]=='W') b=-b;if(tem[2]=='S') c=-c;if(tem[3]=='W') d=-d;//cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;double sum=cal(a,b,c,d)/2.0;cout<<"The distance to the iceberg: ";cout<<fixed<<setprecision(2)<<sum;cout<<" miles."<<endl;if(floor(sum+0.005)<100) cout<<"DANGER!"<<endl;break;}return 0;}
我只想做个努力的人!加油!
0 0
- poj2354——Titanic
- POJ2354-Titanic
- poj2354
- kaggle——Titanic
- Kaggle入门——Titanic案例
- Kaggle练习1——Titanic
- 探索数据集——Titanic
- Kaggle:Titanic问题(3)——经验总结
- Titanic
- Kaggle系列——Titanic 80%+精确度纪录
- Titanic: Machine Learning from Disaster——Linear regression
- Titanic: Machine Learning from Disaster——Logistic regression
- Titanic: Machine Learning from Disaster——Improving submission
- Titanic: Machine Learning from Disaster——总结
- kaggle竞赛——Titanic:Machine Learning from Disaster
- Kaggle竞赛 —— 泰坦尼克号(Titanic)
- Kaggle:Titanic问题(1)——相关库函数操作
- Kaggle:Titanic问题(2)——实现代码
- 第十一章编程练习(4)
- USACO 1.2 transform
- linux 信号 sigsuspend abort
- 程序员的未来之路[转]
- POJ 2420 二分法 模拟退火算法
- poj2354——Titanic
- 常用php curl选项
- Codeforces #342 D. Finals in arithmetic 模拟 构造
- 【slighttpd】基于lighttpd架构的Server项目实战(9)—状态机
- (二)搜索&&广告&&营收
- ADO.NET之删除记录
- linux虚拟机搭建
- JSP脚本和注释
- RESTful三理解