poj2354——求球上两点距离(经纬度)

题目链接:http://poj.org/problem?id=2354

It is a historical fact that during the legendary voyage of "Titanic" the wireless telegraph machine had delivered 6 warnings about the danger of icebergs. Each of the telegraph messages described the point where an iceberg had been noticed. The first five warnings were transferred to the captain of the ship. The sixth one came late at night and a telegraph operator did not notice that the coordinates mentioned were very close to the current ship's position.

Write a program that will warn the operator about the danger of icebergs!

Input

The input messages are of the following format:

Message #<n>.

Received at <HH>:<MM>:<SS>. 

Current ship's coordinates are 

<X1>^<X2>'<X3>" <NL/SL> 

and <Y1>^<Y2>'<Y3>" <EL/WL>.

An iceberg was noticed at 

<A1>^<A2>'<A3>" <NL/SL> 

and <B1>^<B2>'<B3>" <EL/WL>.

===


Here <n> is a positive integer, <HH>:<MM>:<SS> is the time of the message reception, <X1>^<X2>'<X3>" <NL/SL> and <Y1>^<Y2>'<Y3>" <EL/WL> means "X1 degrees X2 minutes X3 seconds of North (South) latitude and Y1 degrees Y2 minutes Y3 seconds of East (West) longitude."

Output

Your program should print to the output file message in the following format:

The distance to the iceberg: <s> miles.


Where <s> should be the distance between the ship and the iceberg, (that is the length of the shortest path on the sphere between the ship and the iceberg). This distance should be printed up to (and correct to) two decimal digits. If this distance is less than (but not equal to!) 100 miles the program should print one more line with the text:

DANGER!

Sample Input

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.
===

Sample Output

The distance to the iceberg: 52.04 miles.
DANGER!

Hint

For simplicity of calculations assume that the Earth is an ideal sphere with the diameter of 6875 miles completely covered with water. Also you can be sure that lines in the input file break exactly as it is shown in the input samples. The ranges of the ship and the iceberg coordinates are the same as the usual range for geographical coordinates, i.e. from 0 to 90 degrees inclusively for NL/SL and from 0 to 180 degrees inclusively for EL/WL.

题目理解

给你一些字符串,其中包含球上两个点的经纬度,求这个点的球上距离,球的直径是6875;

理科生,对经纬度不熟悉,幸亏还是能体会意思,不过要推出来一个公式。

公式:dis(A,B) = R*arccos(cos(wA)*cos(wB)*cos(jB-JA)+sin(wA)*sin(wB));

(wA表示A点的纬度,jA表示A点的精度,B类似),注意默认正方向为'N',’E';

推导公式请参考(关于已知两点经纬度求球面两点的最短距离的公式推导

经纬度wA=(a+b/60.0+c/3600.0)*flag/180*PI(a,b,c分别为经纬度的值,flag为正方向(1或-1),PI为π,用atan(1.0)*4表示)

读数据的时候注意一下。

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstdio> 
using namespace std;
const double PI=atan(1.0)*4;
const double R=6875/2.0;
const double eps=1e-6;
char s[10];
int main(){
	scanf("%*s%*s");
	scanf("%*s%*s%*s");
	scanf("%*s%*s%*s%*s");
	int a,b,c;
	scanf("%d^%d\'%d\"",&a,&b,&c);
	scanf("%s",s);
//	printf("%d %d %d\n",a,b,c);
//	cout<<s<<endl;
	int flag;
	if(s[0]=='N') flag=1;
	else flag=-1;
	double wA=(a+b/60.0+c/3600.0)*flag/180*PI;
	scanf("%*s%d^%d\'%d\"",&a,&b,&c);
	scanf("%s",s);
//	printf("%d %d %d\n",a,b,c);
//	cout<<s<<endl;
	if(s[0]=='E') flag=1;
	else flag=-1;
	double jA=(a+b/60.0+c/3600.0)*flag/180*PI;
	scanf("%*s%*s%*s%*s%*s");
	scanf("%d^%d\'%d\"",&a,&b,&c);
	scanf("%s",s);
//	printf("%d %d %d\n",a,b,c);
//	cout<<s<<endl;
	if(s[0]=='N') flag=1;
	else flag=-1;
	double wB=(a+b/60.0+c/3600.0)*flag/180*PI;
	scanf("%*s%d^%d\'%d\"",&a,&b,&c);
	scanf("%s",s);
	if(s[0]=='E') flag=1;
	else flag=-1;
	double jB=(a+b/60.0+c/3600.0)*flag/180*PI;
	scanf("%*s");
	double dis=R*acos(cos(wA)*cos(wB)*cos(jB-jA)+sin(wB)*sin(wA));
	printf("The distance to the iceberg: %.2f miles.\n",dis);
	dis+=0.005;
	if((dis-100.0)<eps)  printf("DANGER!\n");
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值