URAL 1030 TITANNIC
2015-08-05 14:33
316 查看
计算几何,,,,,,,,,,,,这题太恶心了!!!
求的是球面距离
d(x1,y1,x2,y2)=r*arccos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y1-y2))
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.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!!!")
#define STOP system("pause")
using namespace std;
const double r = 6875.0/2;
const double pi = acos(-1.0);
double angle_3d(double lng1, double lat1, double lng2, double lat2)
{ //经度,纬度,经度,纬度
return acos(cos(lat1)*cos(lat2)*cos(lng1 - lng2) + sin(lat1)*sin(lat2));
}
int main()
{
char s[50];
double x1,x2,x3;
double lng1, lat1, lng2, lat2;
while( ~scanf("%s", s) )
{
if( s[0] == '=' ) break;
for(int i=0; i<8; i++) scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lat1 = x1 + x2/60 + x3/3600;
if( s[0] == 'S' ) lat1 *= -1;
scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lng1 = x1 + x2/60 + x3/3600;
if( s[0] == 'W' ) lng1 *= -1;
for(int i=0; i<5; i++) scanf("%s",s); // iceberg
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lat2 = x1 + x2/60 + x3/3600;
if( s[0] == 'S' ) lat2 *= -1;
scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lng2 = x1 + x2/60 + x3/3600;
if( s[0] == 'W' ) lng2 *= -1;
double ang = angle_3d(lng1*pi/180, lat1*pi/180, lng2*pi/180, lat2*pi/180);
double dis = ang * r;
printf("The distance to the iceberg: %.2lf miles.\n", dis);
if( floor(dis+0.005) < 100 )
printf("DANGER!\n");
}
return 0;
}
求的是球面距离
d(x1,y1,x2,y2)=r*arccos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y1-y2))
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.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!!!")
#define STOP system("pause")
using namespace std;
const double r = 6875.0/2;
const double pi = acos(-1.0);
double angle_3d(double lng1, double lat1, double lng2, double lat2)
{ //经度,纬度,经度,纬度
return acos(cos(lat1)*cos(lat2)*cos(lng1 - lng2) + sin(lat1)*sin(lat2));
}
int main()
{
char s[50];
double x1,x2,x3;
double lng1, lat1, lng2, lat2;
while( ~scanf("%s", s) )
{
if( s[0] == '=' ) break;
for(int i=0; i<8; i++) scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lat1 = x1 + x2/60 + x3/3600;
if( s[0] == 'S' ) lat1 *= -1;
scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lng1 = x1 + x2/60 + x3/3600;
if( s[0] == 'W' ) lng1 *= -1;
for(int i=0; i<5; i++) scanf("%s",s); // iceberg
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lat2 = x1 + x2/60 + x3/3600;
if( s[0] == 'S' ) lat2 *= -1;
scanf("%s",s);
scanf("%lf^%lf'%lf\" %s",&x1, &x2, &x3, s);
lng2 = x1 + x2/60 + x3/3600;
if( s[0] == 'W' ) lng2 *= -1;
double ang = angle_3d(lng1*pi/180, lat1*pi/180, lng2*pi/180, lat2*pi/180);
double dis = ang * r;
printf("The distance to the iceberg: %.2lf miles.\n", dis);
if( floor(dis+0.005) < 100 )
printf("DANGER!\n");
}
return 0;
}
相关文章推荐
- Android init进程——属性服务
- Matlab & C++ 混合编程mex文件的编写与调试
- myeclipse2015工程与jdk版本异常
- hdu 1789 Doing Homework again
- android 问题集锦
- PostgreSQL热备份时pg_start_backup() 做了什么?
- 用ildasm/ilasm修改IL代码(操作步骤)
- ios面试题
- Android编译过程详解(三)
- 设置textbox只能输入数字
- oracle 11g 数据库中报:协议适配器错误
- 安卓系统各版本市场份额
- Android 图形:绘制渐变色奥运五环图形,游戏文字,验证码,Matrix旋转,缩放,倾斜,平移等
- 浅谈USB驱动架构
- ZOJ 3057 Beans Game (博弈入门)
- BW系列之增量机制
- 黑马程序员_Java基础:反射机制(Reflection)总结
- 获得一个日期在当周是否有节日并返回日期
- const对象
- list删除null