UVa 10075 - Airlines(球面距离+Floyd)
来源:互联网 发布:视频剪切软件中文版 编辑:程序博客网 时间:2024/04/29 22:33
这题要求的是球面的航线距离,不是直线距离,而是球面的弧线距离
我先把球面坐标转换为三维坐标,然后计算出两点间距离,再用余弦定理求出扇形角度,从而求出弧线距离
本题的结果要转换成int,否则会有误差
#include <stdio.h>#include <string.h>#include <math.h>const double pi=3.141592653589793;const double R=6378;typedef struct{ char s[25]; double x; double y; double z;}air;air a[110];int d[110][110],inf;double dis(air a,air b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);}int ld(air a,air b){ double dist=dis(a,b); double ang=acos((R*R*2.0-dist)/(2.0*R*R)); return (int)(R*ang+0.5);}int ff(char *s,int n){ for(int i=0;i<n;i++) { if(strcmp(a[i].s,s)==0) return i; }}int main(){ int n,m,q,cas=0; double l,r; char st[25],ed[25]; while(scanf("%d%d%d",&n,&m,&q)==3) { if(!n&&!m&&!q)return 0; if(cas)printf("\n"); memset(d,0x3f,sizeof(d)); inf=d[0][0]; for(int i=0;i<n;i++) { scanf("%s %lf %lf",a[i].s,&l,&r); l=l*pi/180.0; r=r*pi/180.0; a[i].x=R*cos(l)*cos(r); a[i].y=R*cos(l)*sin(r); a[i].z=R*sin(l); } for(int i=0;i<m;i++) { scanf("%s%s",st,ed); int A=ff(st,n); int B=ff(ed,n); d[A][B]=ld(a[A],a[B]); } for(int k=0;k<n;k++) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(d[i][k]+d[k][j]<d[i][j]) d[i][j]=d[i][k]+d[k][j]; } } } printf("Case #%d\n",++cas); for(int i=0;i<q;i++) { scanf("%s%s",st,ed); if(d[ff(st,n)][ff(ed,n)]==inf)puts("no route exists"); else printf("%d km\n",d[ff(st,n)][ff(ed,n)]); } } return 0;}
- UVa 10075 - Airlines(球面距离+Floyd)
- UVA 10075 Airlines (Floyd + 数学转换)
- uva 11817(球面距离)
- UVa Problem 10075 Airlines (航线)
- (beginer) 经纬度转换 UVA 10075 - Airlines
- uva 10075 - Airlines(几何+最短路)
- UVA 10075 Airlines
- UVa 10075 - Airlines
- 球面距离 UVA 11817 Tunnelling the Earth
- UVa 11817 Tunnelling the Earth(球面距离)
- poj 2587(球面距离)
- 球面距离
- UVa 11817 Tunnelling the Earth 计算球面距离
- poj 2354 Titanic(球面两点距离)
- 根据经纬度计算球面距离
- POJ 3407 求球面距离
- 根据经纬度计算球面距离
- 计算球面两点距离 python
- URAL 1519. Formula 1
- python字符串操作
- XOR and OR
- mysql建表
- CF17B Hierarchy
- UVa 10075 - Airlines(球面距离+Floyd)
- AmazingListView+AmazingAdapter
- eclipse中搭建android开发环境笔记
- win7系统如何进行远程控制
- CUDA从入门到精通(零):写在前面
- find the most comfortable road
- linux下c编程起步一:掌握gcc基本用法
- JVM之AccessController访问控制器
- C语言小程序(八)、统计字母个数