Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
投降了,贴一下代码,过了的帮个忙吧?In Reply To:郁闷了,咋就不对呢?输入到底有多少组数据? Posted by:frkstyc at 2005-03-29 23:52:49 #include <stdio.h> #include <math.h> #include <float.h> const double sec = 4.8481368110953599358991410235795e-6; const double radius = 6875.0 / 2; int main(void) { char line[80]; double lat, lng, th, dist; double x1, y1, z1; double x2, y2, z2; int d, m, s; char c; _controlfp(PC_64, MCW_PC); while(scanf("%s", line), line[0] == 'M') { gets(line); gets(line); gets(line); //弄掉前三行 scanf("%d^%d'%d\" %c", &d, &m, &s, &c); s += m * 60 + d * 3600; lat = s * sec; if(c == 'S') { lat = -lat; } gets(line); scanf("and %d^%d'%d\" %c", &d, &m, &s, &c); s += m * 60 + d * 3600; lng = s * sec; if(c == 'W') { lng = -lng; } x1 = cos(lat) * cos(lng); y1 = cos(lat) * sin(lng); z1 = sin(lat);//球坐标到直角坐标 gets(line); gets(line); scanf("%d^%d'%d\" %c", &d, &m, &s, &c); s += m * 60 + d * 3600; lat = s * sec; if(c == 'S') { lat = -lat; } gets(line); scanf("and %d^%d'%d\" %c", &d, &m, &s, &c); s += m * 60 + d * 3600; lng = s * sec; if(c == 'W') { lng = -lng; } x2 = cos(lat) * cos(lng); y2 = cos(lat) * sin(lng); z2 = sin(lat); th = acos(x1 * x2 + y1 * y2 + z1 * z2);//求夹角 dist = th * radius; dist = 0.01 * floor(dist * 100.0);//correct to是截尾吧? gets(line); gets(line); printf("The distance to the iceberg: %.2lf miles.\n", dist); if(dist < 100.0) { puts("DANGER!"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator