UVa 10075 - Airlines
航线算球面距离,需要经纬度转空间坐标。
任意两点间距离用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的更多相关文章
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- UVA 590 二十一 Always on the run
Always on the run Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
随机推荐
- 表达式语言之ongl表达式
OGNL的全称是Object Graph Navigation Language(对象图导航语言),它是一种强大的表达式语言,让你通过简单一致的表达式语法来读取和设置Java对象的属性值,调用对象的方 ...
- GOOGLE影像地图
卫星地图高清 //
- useradd命令详解
功能说明:建立用户帐号.语 法:useradd [-mMnr][-c <备注>][-d <登入目录>][-e <有效期限>][-f <缓冲天数>][-g ...
- 34 个使用 Raspberry Pi 的酷创意
如果你手头有一个 Raspberry Pi(树莓派),你会拿它来做什么?或许以下 34 个如何使用 Raspberry Pi 的创意能够给你带来一些启发. Web 服务器 家庭自动化 BitTorre ...
- iOS10相册相机闪退bug-b
iOS10系统下调用系统相册.相机功能,遇到闪退的情况,描述如下: This app has crashed because it attempted to access privacy-sensit ...
- android 开发 实现自动安装
场景:实现自动安装apk程序 注意:不能使用 intent.setDataAndType(Uri.parse(apkPath), "application/vnd.android.pack ...
- 将Asp.Net MVC应用程序的控制器定义在单独的程序集(类库)中
一直以来都想把控制器的代码部署到单独的程序集里.昨天研究Asp.Net MVC的源代码,偶然发现有一个奇特的类“ControllerBuilder”,MSDN上的介绍相当简略,就一句话“表示一个类,该 ...
- 无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent
无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent 在Flex Application里,是不能直接用addChild添加Sprite ...
- c++ 时间与字符串转换
.时间转字符串函数 size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timep ...
- UVA 12382 Grid of Lamps 贪心
题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...