POJ2354-Titanic
来源:互联网 发布:网页游戏优化 编辑:程序博客网 时间:2024/03/28 19:31
Titanic
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2122 Accepted: 535
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.
Source
Ural Collegiate Programming Contest 1999
//AC代码
/*题意:给出地球上两个点,求出两点之间的距离,如果小于100输出DANGER否则输出距离关于东西经和南北纬,要注意:东经的点的y值都是正值,西经的点的y值都是负值,北纬的点的z值都是正值,南纬的点的z值都是负值*/#include<iostream>#include<queue>#include<cstdio>#include<algorithm>#include<cstring>#include<iomanip>#include<map>#include<cstdlib>#include<cmath>#include<vector>#define LL long long#define IT __int64#define zero(x) fabs(x)<eps#define mm(a,b) memset(a,b,sizeof(a))const int INF=0x7fffffff;const double inf=1e8;const double eps=1e-8;const double PI=acos(-1.0);const int Max=20001;const double R=3437.5;using namespace std;int sign(double x){ return (x>eps)-(x<-eps);}typedef struct Node{ double x; double y; Node(const double &_x=0, const double &_y=0) : x(_x), y(_y) {} void input() { cin>>x>>y; } void output() { cout<<x<<" "<<y<<endl; }}point;double xmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double dmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);}double Distance(point p1,point p2)// 返回两点之间欧氏距离{return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );}double Distance_Angle(double Angle_1,double Angle_2,double Angle_3,double Angle_4){ double theta,dis; Angle_1=Angle_1*PI/180; Angle_2=Angle_2*PI/180; Angle_3=Angle_3*PI/180; Angle_4=Angle_4*PI/180; theta=acos(cos(Angle_1)*cos(Angle_3)*cos(Angle_2-Angle_4)+sin(Angle_1)*sin(Angle_3)); dis=theta*R; return dis;}int main(){ int n,m,i,j; int HH,MM,SS; double dis; double x1,x2,x3; double y1,y2,y3; double a1,a2,a3; double b1,b2,b3; double Angle_1,Angle_2,Angle_3,Angle_4; char str1[100],str2[100],str3[100],str4[100],str5[100]; char c1,c2,c3; while(scanf("%s",&str1)!=EOF) { getchar(); scanf("%c%d%c",&c1,&n,&c2); //cout<<"1: "<<n<<endl; scanf("%s%s",&str1,&str2); scanf("%d:%d:%d.",&HH,&MM,&SS); //cout<<"2: "<<HH<<" "<<MM<<" "<<SS<<endl; scanf("%s%s%s%s",&str1,&str2,&str3,&str4); scanf("%lf%c%lf%c%lf%c",&x1,&c1,&x2,&c2,&x3,&c3); Angle_1=x1+x2/60+x3/3600; scanf("%s",&str1); if(str1[0]=='S')//南经的点值是负值 Angle_1=-Angle_1; //cout<<"3: "<<x1<<" "<<x2<<" "<<x3<<endl; //puts(str1); scanf("%s",&str1); //puts(str1); scanf("%lf%c%lf%c%lf%c",&y1,&c1,&y2,&c2,&y3,&c3); //cout<<"4: "<<y1<<" "<<y2<<" "<<y3<<endl; Angle_2=y1+y2/60+y3/3600; scanf("%s",&str1); if(str1[0]=='W') Angle_2=-Angle_2; //puts(str1); scanf("%s%s%s%s%s",&str1,&str2,&str3,&str4,&str5); scanf("%lf%c%lf%c%lf%c",&a1,&c1,&a2,&c2,&a3,&c3); Angle_3=a1+a2/60+a3/3600; scanf("%s",&str1); if(str1[0]=='S') Angle_3=-Angle_3; //puts(str1); //cout<<"5: "<<a1<<" "<<a2<<" "<<a3<<endl; scanf("%s",&str1); scanf("%lf%c%lf%c%lf%c",&b1,&c1,&b2,&c2,&b3,&c3); Angle_4=b1+b2/60+b3/3600; scanf("%s",&str1); if(str1[0]=='W') Angle_4=-Angle_4; //cout<<"6: "<<b1<<" "<<b2<<" "<<b3<<endl; scanf("%s",&str1); //puts(str1); //cout<<Angle_1<<" "<<Angle_2<<" "<<Angle_3<<" "<<Angle_4<<endl; dis=Distance_Angle(Angle_1,Angle_2,Angle_3,Angle_4); cout<<"The distance to the iceberg: "<<setprecision(2)<<setiosflags(ios::fixed)<<dis<<" miles."<<endl; if(sign(dis-100+0.005)<eps) cout<<"DANGER!"<<endl; } return 0;}/*Message #513.Received at 22:30:11.Current ship's coordinates are41^46'00" NLand 50^14'00" WL.An iceberg was noticed at41^14'11" NLand 51^09'00" WL.===*/
0 0
- POJ2354-Titanic
- poj2354——Titanic
- poj2354
- Titanic
- titanic prediction
- 【kaggle】Titanic
- Kaggle: Titanic
- kaggle:titanic
- titanic+tensorflow
- kaggle-Titanic
- the lose of Titanic
- 重看《Titanic》
- POJ 2354 Titanic
- poj 2354 Titanic
- Ural 1030. Titanic
- Titanic : ML from Disaster
- POJ 2354 Titanic
- Titanic Kaggle 竞赛系列
- 常用sql语句-基础(数据库操作,表操作)
- WIN2003 x64 水晶报表10简单安装部署说明
- spring整合redis
- 【Android】Permission权限访问清单
- linux下搭建SVN服务器
- POJ2354-Titanic
- arm IP寄存器
- countAndSay(leetcode)
- 三国战记风云在起
- dup和dup2函数
- ISO软件工程模板-概要设计说明书
- 安卓系列基础教程之TextView控件
- Hibernate_4_部门与员工实例_一对多、多对一关联关系
- jxl处理报表