Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

算出的距离要四舍五入(+0.005)再和0.0001比较如果小于为0,不然WA到死~

Posted by ecjtu_yuweiwei at 2014-08-05 22:45:53 on Problem 2354
/*
题意:给出地球上两个点,求出两点之间的距离,如果小于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.
===
*/

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator