zoj 1943 || poj 2254 || UVA 535 Globetrotter ( UVA卡精度了 )
来源:互联网 发布:淘宝抢红包怎么抢 编辑:程序博客网 时间:2024/06/16 06:32
蛮水的题,给你N个城市的大地坐标,然后询问。
我查询用map了,应该会快一点哈~好方便滴说。
其他没啥了,就求下距离。
zoj poj AC的代码是先求角度,然后 ang*r是答案。
结果捏 UVA 死活过不去,后来看UVA的discuss,看了人家求距离的函数,贴了过来,过了 = = 。。
应该我的先求角度再求距离的方法被卡精度了。
贴上UVA AC的代码。
#include <set>#include <map>#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define BUG puts("here!!!")using namespace std;const int MAX = 101;const double r = 6378;const double pi = 3.141592653589793;struct NODE{ double lng,lat;};NODE p[MAX];map<string, int> m;double dis_3d(double lng1, double lat1, double lng2, double lat2) { //经度,纬度,经度,纬度 double dlon = lng2 - lng1; double dlat = lat2 - lat1; double a = pow((sin(dlat/2)),2) + cos(lat1) * cos(lat2) * pow(sin(dlon/2), 2); double c = 2 * atan2(sqrt(a), sqrt(1-a)); double d = r * c; return d;}int main(){int i = 0;string s, s1, s2;while( cin >> s ){if( s == "#" ) break;cin >> p[i].lat >> p[i].lng;m.insert( make_pair(s, i) );i++;}while( cin >> s1 >> s2 ){if( s1 == "#" && s2 == "#" ) break;if( !m.count(s1) || !m.count(s2) ){cout << s1 << " - " << s2 << endl;cout << "Unknown" << endl;continue;}int a = m.find(s1)->second;int b = m.find(s2)->second;double dis = dis_3d(p[a].lng*pi/180, p[a].lat*pi/180, p[b].lng*pi/180, p[b].lat*pi/180);dis = floor(dis + 0.5);cout << s1 << " - " << s2 << endl;cout << dis << " km" << endl;}return 0;}
- zoj 1943 || poj 2254 || UVA 535 Globetrotter ( UVA卡精度了 )
- uva 535 - Globetrotter(几何弧面长)
- POJ 2254 Globetrotter
- UVa 10714 & POJ 1852 & ZOJ 2376 - Ants
- POJ 1005 & ZOJ 1049 & UVA 2363
- POJ 2196 & ZOJ 2405 & UVA 3199
- zoj 1892 || poj 2504 || UVA 10577 Bounding box
- zoj 1886 || poj 2540 || UVA 10084 Hotter Colder
- UVa 10714 / POJ 1852 / ZOJ 2376 Ants (等价转化思想)
- POJ 1903 & ZOJ 2469 & UVA 1326 Jurassic Remains (部分枚举)
- UVa 10038 / POJ 2575 / ZOJ 1879 Jolly Jumpers (water ver.)
- ZOJ 1914 Arctic Network (POJ 2349 UVA 10369) MST
- UVa 714 & POJ 1505 & ZOJ 2002 - Copying Books
- zoj 2016 && poj 1386 && uva 10129 Play on Words
- UVA 10341 (二分查找+精度)
- ZOJ 2739 & UVA 3399
- UVA 10200 Prime Time (打表)(精度太坑了)
- UVA 10200 Prime Time (打表)(精度太坑了)
- 2012
- OracleERP-物料
- 自动undo管理下如何添加和删除回滚段
- iphone开发每日一练【2011-08-27】2
- javascript对象概念大全
- zoj 1943 || poj 2254 || UVA 535 Globetrotter ( UVA卡精度了 )
- AsyncTask源码解析
- 关于前置声明
- 高手是怎样练成的
- 深入理解Linux网络内幕学习笔记
- 示波器基础知识扫盲
- java 与 php 体验
- OracleERP-供应商
- iptables感悟--Ubuntu