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 ...
随机推荐
- STM32调试大法 之 串口通讯
开发过程经常需要查看某些特定参数.通常的方法可以使用paintf进行打印输出,观察具体的变量值.STM32内部集成有USART的串口功能,可以通过串口直接输出到电脑(上位机).使用非常方便,基本不需要 ...
- iOS多线程GCD 研究
Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. dispatch queue分成以下三种: 1)运行在主线程的Main queue,通过dispat ...
- 一些 PHP 管理系统程序中的后门
一些php网站管理程序的,一些后门,其实官方也没有恶意,主要是大家为了自己的安全. 我倒不怎么关心提示框,SABLOG怎么知道我的版本有漏洞呢,程序肯定有后门.每次登陆后台自动检测官方版本跟当前版本对 ...
- Css compatibility
http://meiert.com/en/indices/css-properties/ http://www.standardista.com/css3/css3-selector-browser- ...
- 关于 iOS10 更新后 360 云盘 的上传按钮消失的解决方案
最近出了iOS10,作为iOS开发者,果断更新. 但是更新完后,打开自己的360云盘,发现想向云盘上传东西,但是传不了,加号按钮不见了. 经过我的研究,原因是 下面的自定义tabbar放置加号按钮的方 ...
- iOS10相册相机闪退bug-b
iOS10系统下调用系统相册.相机功能,遇到闪退的情况,描述如下: This app has crashed because it attempted to access privacy-sensit ...
- Halcon学习笔记之缺陷检测(一)
例程:surface_scratch.hdev 说明:这个程序利用局部阈值和形态学处理提取表面划痕 代码中绿色部分为个人理解和注释,其余为例程中原有代码 *surface_scratch.hdev:e ...
- webview加载本地html
//webView.loadUrl("file:///android_asset/index.html"); 加载assets目录中含有的index.html webView.l ...
- ffmpeg 打开视频流太慢(上)
新版ffmpeg打开网络视频流需要调用avformat_find_stream_info方法,很多朋友会发现调用改方法耗费很多时间造成打开视频流太慢.有两个参数可以减少avformat_find_st ...
- MySQL数据库双机热备份
MySQL数据库双机热备份 1.mysql 数据库没有增量备份的机制 当数据量太大的时候备份是一个很大的问题.还好 mysql 数据库提供了一种主从备份的机制,其实就是把主数据库的所有的数据同时写到备 ...