閱讀552 返回首頁    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總線域