【2012 - 百度之星资格赛 - I:地图的省钱计划】
I:地图的省钱计划
- 时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
-
百度地图有自己的一套坐标系(你可以把它看作一个笛卡尔坐标系),在这套坐标系里,一个标准单位为1km。而在这坐标系上针对地理信息进行标注的数据,大多数时候是通过购买的方式完成的。为了节约数据更新的成本,数据组里的鑫哥想出了一个好主意——自己测数据。
鑫哥按照他的预想开始实验;在每组试验中,鑫哥选取了三个已经被准确标注在百度地图的坐标系里的移动运营商的基站作为信号接收点(这里可以准确的得到信号的接收时间信息)。当信号接收点附近的用户手机签到时,三个信号接收点就会先后接收到这个信号,并可以准确的知晓接收到信号的时间(将第一个信号点接收到信号的时间记为0秒时刻)。由此,我们就可以确定用户手机签到的位置的在地图的准确坐标了。
现在已知以下数据:
1.三个信号接收点在百度地图坐标系中的具体坐标(x1,y1), (x2,y2), (x3,y3);
2.三个信号点得到用户发出的信号的时间t1, t2, t3(t1, t2, t3 ≥ 0),单位s; t1, t2, t3至少有一个数为0;
3.信号的转播速度C,单位m/s;
请帮助鑫哥写个程序,计算下用户发出信号的位置在百度地图坐标系内的坐标(这个点是唯一的)。 - 输入
- 输入包含多组数据,每组数据格式如下:
C
x1 y1 x2 y2 x3 y3
t1 t2 t3
最后一组数据为0,表示输入结束。 - 输出
- 针对每组测试数据,请先输出这个组的编号(第n组就是输出“Case n:”);然后换行输出信号发出点的坐标(x,y) 。x,y应该由空格分隔,并被舍入到小数点后第六位。
- 样例输入
-
1000 0 1 1 1 2 1 0 0.6 1.6 1000 0 0 0 1 1 0 0.4142135 0 0 1000 0 0 1 0 2 1 0 0.414213562373 1 1000 0 0 0 -1 0 1 0 0 1 1000 0 0 0 1 0 -1 0 1 0 1000 0 0 1 0 -1 0 0 1 0 1000 0 0 -1 0 1 0 0 0 1 100 0 0 0 1 1 0 0 10 10 0
- 样例输出
-
Case 1: 0.200000 1.000000 Case 2: 1.000000 1.000000 Case 3: 0.000000 1.000000 Case 4: 0.000000 -0.500000 Case 5: 0.000000 -0.500000 Case 6: -0.500000 0.000000 Case 7: -0.500000 0.000000 Case 8: 0.000000 0.000000
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cassert> 6 #include <string> 7 #include <algorithm> 8 #include <fstream> 9 #include <sstream> 10 #include <set> 11 #include <map> 12 #include <vector> 13 #include <queue> 14 #include <deque> 15 #include <complex> 16 #include <numeric> 17 using namespace std; 18 double x[10], y[10], t[10]; 19 bool solve(int i, int j, int k) 20 { 21 double x1, y1, x2, y2, t1, t2; 22 x1 = x[j] -x[i]; 23 x2 = x[k] -x[i]; 24 y1 = y[j] -y[i]; 25 y2 = y[k] -y[i]; 26 t1 = t[j] -t[i]; 27 t2 = t[k] -t[i]; 28 29 double A1 = x1*x1 + y1*y1 - t1*t1; 30 double A2 = x2*x2 + y2*y2 - t2*t2; 31 double A = A1*y2-A2*y1, B = A1*x2-A2*x1, C = A1 * t2 - A2 * t1; 32 double cita = atan2(B, A); 33 double sum = asin(- C/sqrt(A*A+B*B+1e-15)); 34 35 double alpha = sum - cita; 36 double r; 37 if (abs(A1)>abs(A2)) 38 r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2; 39 else 40 r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2; 41 42 if (r<0) 43 { 44 sum = - sum + 3.141592653579; 45 alpha = sum - cita; 46 if (abs(A1)>abs(A2)) 47 r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2; 48 else 49 r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2; 50 } 51 52 53 printf("%.6f %.6f\n", r * cos(alpha) + x[i], r * sin(alpha) + y[i]); 54 } 55 int main() 56 { 57 for (int dd = 1; ; ++ dd) 58 { 59 double c; 60 scanf("%lf", & c); 61 c/=1000; 62 if (abs(c) < 1e-6) 63 break; 64 scanf("%lf %lf %lf %lf %lf %lf", x, y, x+1, y+1, x+2, y+2); 65 scanf("%lf %lf %lf", t, t+1, t+2); 66 printf("Case %d:\n", dd); 67 t[0] *= c; 68 t[1] *= c; 69 t[2] *= c; 70 if (solve(0, 1, 2)) 71 continue; 72 } 73 return 0; 74 } 75 76 // end 77 // ism