玲珑杯round#11G题

G – 萌萌哒的第七题
Time Limit:2s Memory Limit:128MByte

Submissions:353Solved:36

DESCRIPTION
Feigay is doing some research about tornado. he drives a car and want to reach the center of the tornado. The center of tornado is (x0, y0) and it is moving at the speed is
(
v
x,
v
y
)
(vx,vy), Feigay is at location (x1, y1) now, his velocity is
v
v. He wants to know whether he is possible to reach that point.

INPUT
The first line contains an integer T (<= 10000), indicates the number of testcase.
Each test case consists of four lines, the first line contains two integers
x
0
,
y
0
x0,y0, the second line contains two integers
x
1
,
y
1
x1,y1, the third line contains two integers
v
x
,
v
y
vx,vy, the fourth line contains one integer
v
v.
The range of every number in the input file is 0 ~ 10000.
OUTPUT
For each test case, print a line contains “YES” if it is possible to reach the center or “NO” if impossible.
SAMPLE INPUT
3
0 0
1 1
1 0
1
0 0
1 1
2 0
1
0 0
2 1
2 0
1
SAMPLE OUTPUT
YES
NO
YES
题意:人的位置在(x1,y1),速率为v(方向任意可变),龙卷风的位置为(x0,y0),速度为(vx,vy),问你人能不能追上龙卷风。
解题思路:这道题坑点比较多,比赛时没有做出来,要考虑人的位置与龙卷风的位置重合了没有,还要考虑二者速度为零的情况,还要考虑人开始就在龙卷风运动的轨迹上,这些特殊情况考虑了之后,一般情况的做法就是先比较二者的速度大小,如果人的速度大,一定能追上,如果相等,那么当人的初始位置与龙卷风的初始位置直接的连线与龙卷风速度的方向形成锐角这时人可以追上,否则不能,若人的速度小于龙卷风的速度,则假设人可以追上,形成一个三角形,设追上时所用时间为t,根据余玄定理列出方程,只含有一个未知数t,列出的方程是个一元二次方程,开口向上,对称轴恒在x轴正半轴,所以,当这个方程的根的判别式大于等于0时,t恒有正数解,这时人可以追上,否则不能。

#include<bits/stdc++.h>
using namespace std;
int x,y;
int x2,y2;
int v;
int vx,vy;
double eps = 1e-10;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&x,&y);
        scanf("%d%d",&x2,&y2);
        scanf("%d%d",&vx,&vy);
        scanf("%d",&v);
        double d = sqrt((double)(x2 - x)*(x2 - x) + (double)(y2 - y)*(y2 - y));
        if(x == x2&&y == y2)//重合
        {
            printf("YES\n");
            continue;
        }
        if(vx == 0&&vy == 0)//静止
        {
            if(v == 0) printf("NO\n");
            else printf("YES\n");
        }
        else if(v == 0)
        {
            if(vx == 0)
            {
               if(x == x2&&y <= y2) printf("YES\n");
               else printf("NO\n");
            }
            else if(vy == 0)
            {
                if(y == y2&&x <= x2) printf("YES\n");
                else printf("NO\n");
            }
            else
            {
                double k = (double)vy/(double)vx;
                double yy = k*x2 - k*x + y;
                if(fabs(yy - (double)y2) <= eps&&y2 >= y) printf("YES\n");
                else printf("NO\n");
            }
        }
        else if(vx == 0)//k 不存在
        {
            if(v > vy) printf("YES\n");
            else if(v == vy)
            {
                if(y2 > y) printf("YES\n");
                else printf("NO\n");
            }
            else
            {
                if(y2 <= y) printf("NO\n");
                else
                {
                    double m = (double)abs(y2 - y)/d;
                    if((double)v*v - (1 - m*m)*vy*vy >= eps) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        else if(vy == 0)//k == 0
        {
            if(v > vx)
            {
                printf("YES\n");
            }
            else if(v == vx)
            {
                if(x2 > x) printf("YES\n");
                else printf("NO\n");
            }
            else
            {
                if(x2 <= x) printf("NO\n");
                else
                {
                    double m = double(x2 - x)/d;
                    if((double)v*v - (1 - m*m)*vx*vx >= eps) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        else//k存在,且不为零
        {
            double v1 = sqrt((double)vx*vx + (double)vy*vy);
            double v2 = (double)v;
            if(v2 - v1 > eps) printf("YES\n");
            else if(fabs(v2 - v1) < eps)
            {
                double k1 = (double)vy/(double)vx;
                double k2 = -1/k1;
                double _x = (k1*x - k2*x2 + y2 - y)/(k1 - k2);
                double _y = k1*_x + y - k1*x;
                double d2 = sqrt((x - _x)*(x - _x) + (y - _y)*(y - _y));
                if(_y - y > eps) printf("YES\n");
                else printf("NO\n");
            }
            else
            {
                double k1 = (double)vy/(double)vx;
                double k2 = -1/k1;
                double _x = (k1*x - k2*x2 + y2 - y)/(k1 - k2);
                double _x0 = (double)x;
                if(_x - _x0 <= eps) printf("NO\n");
                else
                {
                    double _y = k1*_x + y - k1*x;
                    //double d1 = sqrt((x2 - _x)*(x2 - _x) + (y2 - _y)*(y2 - _y));
                    double d2 = sqrt((x - _x)*(x - _x) + (y - _y)*(y - _y));
                    double m = d2/d;
                    if(v2*v2 - (1 - m*m)*v1*v1 >= eps) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值