POJ2354-Titanic

Titanic
Time Limit: 1000MS Memory Limit: 65536K
Total 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!

Input

The input messages are of the following format:  
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:  
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 at
41^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

//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 are
41^46'00" NL
and 50^14'00" WL.
An iceberg was noticed at
41^14'11" NL
and 51^09'00" WL.
===
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值