栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2412 Equidistance

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2412 Equidistance

#include<iostream>#include<math.h>#include<algorithm>#include<stdio.h>#include<string.h>using namespace std;const int Max = 20 + 10;const int CityMax = 110;const double PI = 3.1415926;const double Radius = 6378.0;struct City{char name[Max];double latitude, longitude;double x, y, z;friend bool operator == (const City & a, const City &b){if(!strcmp(a.name, b.name)) return true;else return false;}};City c[CityMax];struct Vector{double x, y, z;};double radian(double d){return d * PI / 180.0;}double square(double d){return d * d;}double angle(Vector &v, City &c){return acos((v.x * c.x + v.y * c.y + v.z * c.z) / sqrt( square(v.x) + square(v.y) + square(v.z) ) / sqrt( square(c.x) + square(c.y) + square(c.z) ));}City * findCity(City *first, City *end, City &c){while(first != end){if(!strcmp(first->name, c.name)) return first;first ++;}return first;}int main(){int index = 0;City A, B, C;while(scanf("%s", c[index].name) && strcmp(c[index].name, "#") != 0){scanf("%lf %lf", &c[index].latitude, &c[index].longitude);c[index].x = Radius * cos(radian(c[index].latitude)) * sin(radian(c[index].longitude));c[index].y = Radius * cos(radian(c[index].latitude)) * cos(radian(c[index].longitude));c[index].z = Radius * sin(radian(c[index].latitude));index ++;}Vector vec;double ang, dist;while(scanf("%s", A.name) && strcmp(A.name, "#")){scanf("%s %s", B.name, C.name);City * a, * b, *cen;a = find(c, c+index, A), b = find(c, c+index, B), cen = find(c, c+index, C); if(a == c+index || b == c+index || cen == c+index){printf("%s is ? km off %s/%s equidistance.n", C.name, A.name, B.name);}else{vec.x = a->x - b->x, vec.y = a->y - b->y, vec.z = a->z - b->z;if(vec.x == 0.0 && vec.y == 0.0 && vec.z == 0.0) dist = 0;else {ang = fabs(PI/2 - angle(vec, *cen));dist = ang*Radius + 0.5;}printf("%s is %d km off %s/%s equidistance.n", C.name, (int)(dist), A.name, B.name);}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370367.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号