poj 2354 || URAL 1030 Titanic

本文介绍了一种计算地球表面两点间球面距离的方法,通过经纬度转换和球面余弦公式实现精确测量,特别关注了不同地理坐标表示方式的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

大地坐标系求球面距离

无聊题啊,坑姐题啊。。

输入真。。。。纠结。

需要注意的就是经度,纬度转化,因为给的是东经神马的,西经神马的,北纬,南纬。。。

最后和100对比是需要和四舍五入后的dis去对比的。各种纠结。。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")

using namespace std;

const double r = 6875.0/2;
const double pi = acos(-1.0);
double angle_3d(double lng1, double lat1, double lng2, double lat2)
{           //经度,纬度,经度,纬度 
    return acos(cos(lat1)*cos(lat2)*cos(lng1 - lng2) + sin(lat1)*sin(lat2));
}

int main()
{
	char s[50];
	
	double x1,x2,x3;
	
	double lng1, lat1, lng2, lat2;
	
	while( ~scanf("%s", s) )
	{
		if( s[0] == '=' ) break;
		for(int i=0; i<8; i++) scanf("%s",s);
		
		scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
		lat1 = x1 + x2/60 + x3/3600;
		if( s[0] == 'S' ) lat1 *= -1;
		
		scanf("%s",s);
		
		scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
		lng1 = x1 + x2/60 + x3/3600;
		if( s[0] == 'W' ) lng1 *= -1;
		
		for(int i=0; i<5; i++) scanf("%s",s);		// iceberg
	
		scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
		lat2 = x1 + x2/60 + x3/3600;
		if( s[0] == 'S' ) lat2 *= -1;
		
		scanf("%s",s);
		
		scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
		lng2 = x1 + x2/60 + x3/3600;
		if( s[0] == 'W' ) lng2 *= -1;
		
		double ang = angle_3d(lng1*pi/180, lat1*pi/180, lng2*pi/180, lat2*pi/180);
		double dis = ang * r;
		
		printf("The distance to the iceberg: %.2lf miles.\n", dis);
		
		if( floor(dis+0.005) < 100  )
			printf("DANGER!\n");
	}

return 0;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值