百度之星资格赛 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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<string>
#include<algorithm>
#include<fstream>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<complex>
#include<numeric>
using namespace std;
double x[10], y[10], t[10];
bool solve(int i, int j, int k)
{
    double x1, y1, x2, y2, t1, t2;
    x1 = x[j] -x[i];
    x2 = x[k] -x[i];
    y1 = y[j] -y[i];
    y2 = y[k] -y[i];
    t1 = t[j] -t[i];
    t2 = t[k] -t[i];
    
    double A1 = x1*x1 + y1*y1 - t1*t1;
    double A2 = x2*x2 + y2*y2 - t2*t2;
    double A = A1*y2-A2*y1, B = A1*x2-A2*x1, C = A1 * t2 - A2 * t1;
    double cita = atan2(B, A);
    double sum = asin(- C/sqrt(A*A+B*B+1e-15));
    
    double alpha = sum - cita;
    double r;
    if (abs(A1)>abs(A2))
        r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;
    else
        r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;
    
    if (r<0)
    {
        sum = - sum + 3.141592653579;
        alpha = sum - cita;
        if (abs(A1)>abs(A2))
            r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;
        else
            r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;
    }
            
        
    printf("%.6f %.6f\n", r * cos(alpha) + x[i], r * sin(alpha) + y[i]);
}
int main()
{
    for (int dd = 1; ; ++ dd)
    {
        double c;
        scanf("%lf", & c);
        c/=1000;
        if (abs(c) < 1e-6)
            break;
        scanf("%lf %lf %lf %lf %lf %lf", x, y, x+1, y+1, x+2, y+2);
        scanf("%lf %lf %lf", t, t+1, t+2);
        printf("Case %d:\n", dd);
        t[0] *= c;
        t[1] *= c;
        t[2] *= c;
        if (solve(0, 1, 2))
            continue;        
    }
    return 0;
}

原文地址:https://www.cnblogs.com/kuangbin/p/2524931.html