poj 3407 Brookebond s'en va en guerre... && poj 2354 Titanic

题意:这奇葩的题题目看着是不是很不像英语。。。没错。。这尼玛好像是法语。。。。orz。。,大致意思就是求两个点的球面距离,不过给的是经纬度坐标

思路:公式题。。套公式就好了

/*
球面距离公式
dis = r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2)) ;
 
其中a1,a2表示维度(北正南负),b1,b2表示经度(东正西负)。R为球的半径
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
char s[100],s1[100];
const double pi=acos(-1.0);
double solve(double a,double c,char s[])
{
	a=a+c/60;
	if(s[0]=='S' || s[0]=='W')
		a=-a;
	a=a*pi/180;
	return a;
}
int main()
{
	double a,b,c,d;
	double p1x,p2x,p1y,p2y;
	while(~scanf("%lf%lf%s%lf%lf%s",&a,&b,s1,&c,&d,s))
	{
		p1x=solve(a,b,s1);
		p1y=solve(c,d,s);
		scanf("%lf%lf%s%lf%lf%s",&a,&b,s1,&c,&d,s);
		p2x=solve(a,b,s1);
		p2y=solve(c,d,s);
		double xx= acos(sin(p1x) * sin(p2x) + cos(p1x) * cos(p2x) * cos(p2y - p1y)) * 6370;
		printf("%.3lf\n",xx);
	}
	return 0;
}

poj 2354

尼玛的。。这题输入格式为什么这么坑。。

/*
球面距离公式
dis = r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2)) ;

其中a1,a2表示维度(北正南负),b1,b2表示经度(东正西负)。R为球的半径
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
char s[1000],s1[1000];
const double pi=acos(-1.0);
const double eps=1e-8;
double solve(double a,double b,double c,char s[])
{
	a=a+c/3600+b/60;
	if(s[2]=='S' || s[2]=='W')
		a=-a;
	a=a*pi/180;
	return a;
}
int dblcmp(double k)
{
	if(fabs(k)<eps)
		return 0;
	return k>0?1:-1;
}
int main()
{
	double a,b,c;
	double a1,b1,a2,b2;
	while(gets(s))
	{
		gets(s);
		gets(s);
		scanf("%lf^%lf'%lf",&a,&b,&c);
		gets(s);
		a1=solve(a,b,c,s);
		scanf("and %lf^%lf'%lf",&a,&b,&c);
		gets(s);
		b1=solve(a,b,c,s);



		gets(s);
		scanf("%lf^%lf'%lf",&a,&b,&c);
		gets(s);
		a2=solve(a,b,c,s);
		scanf("and %lf^%lf'%lf",&a,&b,&c);
		gets(s);
		b2=solve(a,b,c,s);
		gets(s);
		double xx=6875.0/2;
		xx=xx*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));
		printf("The distance to the iceberg: %.2lf miles.\n",xx);
		if(dblcmp(xx-100+0.005)<0)
			printf("DANGER!\n");
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值