航线算球面距离,需要经纬度转空间坐标。

任意两点间距离用Floyd求出来,查询时直接查表。

 #include <cstdio>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib> using namespace std; const int MAXN = ;
const double INF = 1e30;
const double eps = 1e-;
const double PI = acos( -1.0 ); struct Point
{
double x, y;
Point( int x = , int y = ): x(x), y(y) {}
}; struct Coordinate //空间坐标
{
double x, y, z;
}; double dist[MAXN][MAXN];
Coordinate C[MAXN]; double Cha( double a, double b )
{
return (a - b)*(a - b);
} double GetDis( Coordinate a, Coordinate b ) //三维空间直线距离
{
return sqrt( Cha( a.x, b.x ) + Cha( a.y, b.y ) + Cha( a.z, b.z ) );
} double toRad( double deg ) //角度转弧度
{
return deg / 180.0 * acos( -1.0 );
} void get_coord( double R, double lat, double lng, double &x, double &y, double &z ) //经纬度转空间坐标
{
lat = toRad(lat);
lng = toRad(lng);
x = R*cos(lat)*cos(lng);
y = R*cos(lat)*sin(lng);
z = R*sin(lat);
return;
} void Floyd( int n ) //弗洛伊德算任意两点最短路
{
for ( int k = ; k < n; ++k )
for ( int i = ; i < n; ++i )
for ( int j = ; j < n; ++j )
{
double temp = dist[i][k] + dist[k][j];
if ( temp < dist[i][j] ) dist[i][j] = temp;
}
return;
} int main()
{
int n, m, Q;
double r = ;
int cas = ;
bool flag = false;
while ( scanf( "%d%d%d", &n, &m, &Q ), n || m || Q )
{
map<string, int> Map;
for ( int i = ; i < n; ++i )
{
char str[];
Point P;
scanf("%s%lf%lf", str, &P.x, &P.y );
get_coord( r, P.x, P.y, C[i].x, C[i].y, C[i].z );
Map[ str ] = i;
} for ( int i = ; i <= n; ++i )
for ( int j = ; j <= n; ++j )
dist[i][j] = INF; for ( int i = ; i < m; ++i )
{
char str1[], str2[];
scanf( "%s%s", str1, str2 );
int u = Map[ str1 ];
int v = Map[ str2 ];
dist[u][v] = (int)( 2.0 * asin( GetDis( C[u], C[v] ) / ( 2.0 * r ) ) * r + 0.5 ); //四舍五入
} Floyd( n ); if ( flag ) puts(""); printf( "Case #%d\n", ++cas ); while ( Q-- )
{
char str1[], str2[];
scanf( "%s%s", str1, str2 );
int u = Map[ str1 ];
int v = Map[ str2 ];
if ( dist[u][v] >= INF - eps ) puts( "no route exists" );
else printf( "%.0f km\n", dist[u][v] );
} flag = true;
}
return ;
}

UVa 10075 - Airlines的更多相关文章

  1. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  2. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  3. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  4. UVA 590 二十一 Always on the run

     Always on the run Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. 【转载】Powershell获取世纪互联Office365中所有用户的OWA时区

    get-mailbox -resultsize unlimited | Get-MailboxRegionalConfiguration | select Identity,TimeZone | wh ...

  2. PAT IO-03 整数均值

    /* *PAT IO-02 整数四则运算 *2015.7.30 *作者:flx413 */ #include<stdio.h> int main() { ], sum; float ave ...

  3. thinkphp join 查询

    $user=M('user')->table(C('DB_PREFIX').'user as a')->join(C('DB_PREFIX').'role_user as b on a.u ...

  4. TCP/IP, HTTP, socket

    摘自:http://jingyan.baidu.com/article/08b6a591e07ecc14a80922f1.html http://goodcandle.cnblogs.com/arch ...

  5. 团队作业week2-软件分析和用户需求调查

    我们的团队选择评定的软件是必应词典(iphone版)和使用较多的有道词典(iphone版)   类别 描述 评分(Bing) 评分(有道)  功能      核心功能1:词典 顾名思义,作为一款词典类 ...

  6. Could not find file '..\bin\hibernate.cfg.xml'解决方法:

    web.config: 解决方法:

  7. 学习Linux第二天

    1.Linux目录: 保存系统命令:根目录下的bin和sbin,usr下的bin和sbin /etc:保存配件 /usr:系统软件资源目录 /proc:系统内存分配目录,直接写入内存的 /var:保存 ...

  8. java,图片压缩,略缩图

    在网上找了两个图片的缩放类,在这里分享一下: package manager.util; import java.util.Calendar; import java.io.File; import ...

  9. Codeforces Gym 100342J Problem J. Triatrip 三元环

    题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...

  10. 【BZOJ】【1965】SHUFFLE 洗牌

    扩展欧几里德+快速幂 每次转换位置:第x位的转移到2*x %(n+1)这个位置上 那么m次后就到了(2^m)*x %(n+1)这个位置上 那么找洗牌m次后在 l 位置上的牌就相当于解线性模方程: (2 ...