首页 > 代码库 > Asakura的魔法世界

Asakura的魔法世界

Font Size:AaAaAa

Description

Asakura存在于一个魔法世界中。

有一天,Asakura在一条魔法通道里偷懒,突然接到一个紧急任务,要高速赶往还有一条通道b去。 我们把通道a和b看作两条线段AB和CD。Asakura初始位置在A,如今要高速赶往D。

Asakura在魔法通道a上的速度为v1。在魔法通道b上速度为v2,在除了这两条通道上的其余位置的速度为v3。Asakura最快多长时间才干到达指定位置。

Input

多组输入
对于每组測试数据:包括三行
第一行输入四个整数x1,y1,x2,y2.当中(x1,y1)为A。(x2,y2)为B.(-10000<=x1,y1,x2,y2<=10000)
第二行输入四个整数x3,y3,x4,y4.当中(x3,y3)为C,(x4,y4)为D.(-10000<=x3,y3,x4,y4<=10000)
第三行输入三个整数v1,v2,v3.(1<=v1,v2,v3<=50)
每两组測试数据间输入一个空行。

Output

输出A到D最短的时间。结果精度到小数点后两位(四舍五入)。

Sample Input

0 0 50 50
50 0 50 50
1 1 1

0 0 50 50
50 0 50 50
3 1 3

0 0 50 50
50 0 50 50
1 3 1

Sample Output

70.71
23.57
63.81



代码例如以下:
#include<cstdio>
#include<cmath>
doubledis(doublex1, double y1,double x2,double y2)
{
    returnsqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
doublev1, v2, v3, x[4], y[4];
doublemindis(doublexi,double yi)
{
    doublei = x[3] - x[2];
    doublej = y[3] - y[2];
    doublel = 0, r = 1;
    intt;
    doubletmid, tmidmid;
    for(t = 1; t <= 50; t++)
    {
        doublemid = (l + r) / 2;
        doublemidmid = (mid + r) / 2;
        doublemidx = x[2] + mid*i;
        doublemidy = y[2] + mid*j;
        doublemidmidx = x[2] + midmid*i;
        doublemidmidy = y[2] + midmid*j;
        tmid = dis(xi, yi, midx, midy) / v3 + dis(midx, midy, x[3], y[3]) / v2;
        tmidmid = dis(xi, yi, midmidx, midmidy) / v3 + dis(midmidx, midmidy, x[3], y[3]) / v2;
        if(tmid > tmidmid)
            l = mid;
        elser = midmid;
    }
    returntmidmid;
}
int main()
{
    while(~scanf("%lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1]))
    {
        scanf("%lf %lf %lf %lf", &x[2], &y[2], &x[3], &y[3]);
        scanf("%lf %lf %lf", &v1, &v2, &v3);
        doublei = x[1] - x[0];
        doublej = y[1] - y[0];
        doublel = 0, r = 1;
        intt;
        doubletmid, tmidmid;
        for(t = 1; t <= 50; t++)
        {
            doublemid = (l + r) / 2;
            doublemidmid = (mid + r) / 2;
            doublemidx = x[0] + mid*i;
            doublemidy = y[0] + mid*j;
            doublemidmidx = x[0] + midmid*i;
            doublemidmidy = y[0] + midmid*j;
            tmid = dis(x[0], y[0], midx, midy) / v1 + mindis(midx, midy);
            tmidmid = dis(x[0], y[0], midmidx, midmidy) / v1 + mindis(midmidx, midmidy);
            if(tmid > tmidmid)
                l = mid;
            elser = midmid;
        }
        printf("%.2lf\n", tmid);
    }
    return0;
}

Asakura的魔法世界