POJ 2354 Titanic

题目描述

在这里插入图片描述
在这里插入图片描述
本题是求球体两点的距离,直接套用公式即可

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
 
using namespace std;
 
double dist( double l1, double d1, double l2, double d2 )
{
	double r = 6875.0/2;
	double p = acos(-1.0);
	
	l1 *= p/180;d1 *= p/180;
	l2 *= p/180;d2 *= p/180;
	
	return r*acos(cos(l1)*cos(l2)*cos(d1-d2)+sin(l1)*sin(l2));
}
 
int main()
{
	char   temp[100];
	double d,m,s,l1,l2,d1,d2,dis;
	
	for ( int i = 0 ; i < 9 ; ++ i ) scanf("%s",temp);
	scanf("%lf^%lf'%lf\" %s",&d,&m,&s,temp);
	l1 = d+m/60+s/3600;
	if ( temp[0] == 'S' ) l1 *= -1;
	
	scanf("%s",temp);
	scanf("%lf^%lf'%lf\" %s.",&d,&m,&s,temp);
	d1 = d+m/60+s/3600;
	if ( temp[0] == 'W' ) d1 *= -1;
	
	for ( int i = 0 ; i < 5 ; ++ i ) scanf("%s",temp);
	scanf("%lf^%lf'%lf\" %s",&d,&m,&s,temp);
	l2 = d+m/60+s/3600;
	if ( temp[0] == 'S' ) l2 *= -1;
	
	scanf("%s",temp);
	scanf("%lf^%lf'%lf\" %s.",&d,&m,&s,temp);
	d2 = d+m/60+s/3600;
	if ( temp[0] == 'W' ) d2 *= -1;
	
	scanf("%s",temp);	
	dis = dist(l1,d1,l2,d2);
	printf("The distance to the iceberg: %.2lf miles.\n",dis);
	if ( floor(dis+0.005) < 100 ) printf("DANGER!\n");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值