uva 535 - Globetrotter(几何弧面长)

942 篇文章 2 订阅
99 篇文章 0 订阅

题目链接:uva 535 - Globetrotter


#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
//Lab  =  R * arccos(cos(wa)*cos(wb)*cos(ja-jb)  +  sin(wa)*sin(wb))

const int maxn = 105;
const double pi = 4 * atan(1.0);
const double R = 6378.0;
map<string, int> G;
double lat[maxn], lot[maxn];

double toRad(double x) { return x / 180 * pi; }
double solve (int i, int j) {
	//return R * acos(cos(lat[i])*cos(lat[j])*cos(lot[j]-lot[i]) + sin(lat[i])*sin(lat[j]));
	double dlot = lot[j] - lot[i];
	double dlat = lat[j] - lat[i];
	double a = pow(sin(dlat/2), 2) + cos(lat[i])*cos(lat[j])*pow(sin(dlot/2), 2);
	double c = 2 * atan2(sqrt(a), sqrt(1-a));
	return c * R;
}

int main () {
	int n = 0;
	char s[50], t[50];
	G.clear();

	while (scanf("%s", s) == 1 && s[0] != '#') {
		scanf("%lf%lf", &lat[n], &lot[n]);
		string tmp = s;
		G[tmp] = n++;
	}
	
	for (int i = 0; i < n; i++) {
		lat[i] = toRad(lat[i]);
		lot[i] = toRad(lot[i]);
	}

	while (scanf("%s%s", s, t) == 2) {
	   	if (s[0] == '#' && t[0] == '#') break;
		string tmp1 = s, tmp2 = t;
		if (G.find(tmp1) == G.end() || G.find(tmp2) == G.end()) {
			printf("%s - %s\nUnknown\n", s, t);
			continue;
		}
		int a = G[tmp1], b = G[tmp2];
		printf("%s - %s\n%.0lf km\n", s, t, solve(a, b));
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值