UVa10075 - Airlines(所有点对之间的最短距离)

简介: UVa10075 - Airlines(所有点对之间的最短距离)
#include <cstdio>#include <map>#include <string>#include <cmath>#include <algorithm>usingnamespacestd;
constintN=110, INF=0x3f3f3f3f;
constintSTRLEN=25;
constdoublePI=acos(-1);
constintR=6378;
structLocation{
doublelati, longti;
};
Locationlocation[N];
intf[N][N];
intn, m, q;
map<string, int>strMap;
intt;
boolinput();
voidsolve();
intdis(inta, intb);
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif // ONLINE_JUDGEt=1;
while (input()) {
solve();
    }
return0;
}
boolinput()
{
strMap.clear();
scanf("%d%d%d", &n, &m, &q);
if (n==0&&m==0&&q==0) returnfalse;
charbuf[STRLEN];
for (inti=0; i<n; i++) {
scanf("%s%lf%lf", buf, &location[i].lati, &location[i].longti);
stringstr=buf;
strMap[str] =i;
    }
for (inti=0; i<n; i++) {
for (intj=0; j<n; j++) {
if (i==j) f[i][j] =0;
elsef[i][j] =INF;
        }
    }
for (inti=0; i<m; i++) {
scanf("%s", buf);
strings=buf;
intu=strMap[s];
scanf("%s", buf);
s=buf;
intv=strMap[s];
f[u][v] =dis(u, v);
    }
returntrue;
}
intdis(inta, intb)
{
doublealpha=location[a].lati/180*PI;
doublebelta=location[a].longti/180*PI;
doublez1=R*sin(alpha);
doublex1=R*cos(alpha) *cos(belta);
doubley1=R*cos(alpha) *sin(belta);
alpha=location[b].lati/180*PI;
belta=location[b].longti/180*PI;
doublez2=R*sin(alpha);
doublex2=R*cos(alpha) *cos(belta);
doubley2=R*cos(alpha) *sin(belta);
doubletheta=acos((x1*x2+y1*y2+z1*z2) /R/R);
return (int)round(R*theta);
}
voidsolve()
{
for (intk=0; k<n; k++) {
for (inti=0; i<n; i++) {
for (intj=0; j<n; j++) {
if (f[i][k] !=INF&&f[k][j] !=INF) {
f[i][j] =min(f[i][j], f[i][k] +f[k][j]);
                }
            }
        }
    }
if (t>1) printf("\n");
printf("Case #%d\n", t++);
for (inti=0; i<q; i++) {
charbuf1[STRLEN], buf2[STRLEN];
scanf("%s%s", buf1, buf2);
strings1=buf1, s2=buf2;
intu=strMap[s1], v=strMap[s2];
if (f[u][v] !=INF) {
printf("%d km\n", f[u][v]);
        } else {
printf("no route exists\n");
        }
    }
}
目录
相关文章
|
5月前
|
人工智能 BI
【每日一题Day354】LC2316统计无向图中无法互相到达点对数 | 并查集
【每日一题Day354】LC2316统计无向图中无法互相到达点对数 | 并查集
26 0
|
5月前
【每日一题Day218】LC1091 二进制矩阵中的最短路径 | BFS
【每日一题Day218】LC1091 二进制矩阵中的最短路径 | BFS
14 0
|
存储
【每日一题Day106】LC1129 颜色交替的最短路径 | BFS
返回长度为 n 的数组 answer,其中 answer[X] 是从节点 0 到节点 X 的红色边和蓝色边交替出现的最短路径的长度。如果不存在这样的路径,那么 answer[x] = -1。
131 0
|
机器学习/深度学习 定位技术
【每日一题Day109】LC1210穿过迷宫的最少移动次数 | BFS+dp
思路:使用BFS搜索,队列中存放三元组[蛇尾的横轴坐标x,蛇尾的纵轴坐标y,蛇的状态],当蛇为水平时,状态为0;当蛇为竖直时,状态为1
94 1
【每日一题Day109】LC1210穿过迷宫的最少移动次数 | BFS+dp
AcWing 616. 两点间的距离
AcWing 616. 两点间的距离
66 0
AcWing 616. 两点间的距离
AcWing 617. 距离
AcWing 617. 距离
59 0
AcWing 617. 距离
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
我们可以很轻松地发现,被提出的都是在点双连通分量之外的,比如该图中的1 和 5 ,那么怎么判断哪些点不在环中呢? 此时我们还可以逆向思考,不 在 环 中 的 = = 总 的 − 在 环 中 的,所以说现在问题就转换成了满足条件的环内的点的个数
98 0
[UVA1364 | POJ | NC]Knights of the Round Table | Tarjan 求点双 | 二分图 | 综合图论
|
Go
[Nowcoder / POJ2728] 最优比率生成树 | 二分 + prim
有n个点,其中,每个点给出位置坐标( x , y ) 以及高度z ,两点之间的距离为两点之间的欧几里得距离 两点之间建立一条路的代价为两点之间的高度差,问将n 个点联通的情况下,求出最大的cost/dis
104 0
|
人工智能 Prometheus Cloud Native
牛客第五场 B Graph最小异或生成树
这道题涉及到最小异或生成树,要理解这个首先要明白 01字典树 关于01字典树呢,先来一道板子题hdu4825 ==》 不方便跳转的同学们可以看下面的题 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。Prometheus 为了让 Zeus 看到人类的伟大,随即同意 Zeus 可以向人类求助。
101 0
牛客第五场 B Graph最小异或生成树