阅读552 返回首页    go 阿里云 go 技术社区[云栖]


POJ 2354 求球面两点距离

题意:给出球面上两点经纬度,计算球面两点距离。输入输出比较恶心。

公式题 直接上公式就能A。

#include<cmath>  
#include<cstdio>  
#include<iostream>  
using namespace std;  
double a1,b1,a2,b2,d,r=6875/2.0;  
char s[99];  
double Dis3D(double a1,double b1,double a2,double b2)  
{  
    return r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));  
}  
int Get()  
{  
    int a=0;  
    char c;  
    while((c=getchar())<'0'||c>'9');  
    for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';  
    return a;  
}  
void GetA(double &a)  
{  
    a=Get()+Get()/60.0+Get()/3600.0;  
    scanf("%s",s);  
    if(s[0]=='S'||s[0]=='W')a=-a;  
    a=a*acos(-1.0)/180;  
}  
int main()  
{  
    while(gets(s),s[0]!='=')  
    {  
        GetA(a1),GetA(a1),GetA(b1),GetA(a2),GetA(b2);  
        d=Dis3D(a1,b1,a2,b2);  
        printf("The distance to the iceberg: %.2lf miles.\n",d);  
        if(floor(d+0.005)<100)puts("DANGER!");  
        gets(s);  
    }  
    return 0;  
}  


最后更新:2017-04-03 16:48:39

  上一篇:go 3.3.1 Cache一致性的基本概念
  下一篇:go 2.1 存储器域与PCI总线域