Running For Life(找线方程+细节)

Running For Life

One day,poor Bob had a dream.In his dream,he was being chased by a mystery man.Bob was so afraid that he ran so fast than ever.However,Bob knows that as long as his shortest distance with the mystery man is larger than the safe distance,then he will be safe.

Suppose that Bob and the mystery man were in a perfect 2D plane.Bob’s initial location was (Xb,Yb),and the mystery man’s initial location was (Xm,Ym).Also,Bob’s speed was given by (Vxb,Vyb),and the mystery man’s speed was (Vxm,Vym),and they both keep their speed constant during the whole dream!

Luckily,Bob also know about his safe distance,which was sd.However,Bob forgot whether he was safe at last,so he asks you,the smart ACMer,for help.

Input

There are about 1000 test cases.Each case contains a line which describe nine integer:Xb,Yb,Xm,Ym,Vxb,Vyb,Vxm,Vym,sd,(-1e6<=Xb,Yb,Xm,Ym,Vxb,Vyb,Vxm,Vym<=1e6,0<=sd<=1e6)

Output

If Bob was safe at last,please output “Lucky Bob!”,else please output “Poor Bob!”(without quotations).

Sample Input

6 2 7 3 7 0 5 1 0

4 3 1 0 2 0 4 4 6

Sample Output

Lucky Bob!

Poor Bob!


思路:

由Bob和man的初始位置和常速度的方向可以在直角坐标系中,找出他们关于时间的位置坐标,构建距离的方程式并分类求最短距离,与安全距离比较即可

注意:

1、代码中算出来的最短距离没有开方,相应的安全距离也要平方,且数据类型为long long类
2、位置,速度的数据范围为-1e6到1e6,需要用long long类型存储a,b,c,且先除后乘

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;


int main()
{
    LL xb,yb,xm,ym,vxb,vyb,vxm,vym,sd;
    while(cin>>xb>>yb>>xm>>ym>>vxb>>vyb>>vxm>>vym>>sd)
    {
        LL x=xm-xb;
        LL y=ym-yb;
        LL vx=vxm-vxb;
        LL vy=vym-vyb;
        LL a=vx*vx+vy*vy;
        LL b=2*x*vx+2*y*vy;
        LL c=x*x+y*y;
        sd=sd*sd;        //最短距离没有开方,安全距离需要平方
        bool res;
        if(a==0)           //a,b,c分别为0时的分类
            if(b>=0) if(c>sd) res=true;
                    else res=false;
            else res=false;
        else if(b>=0)
            if(c>sd) res=true;
            else    res=false;
        else
        {
            double s=c-(b/4.0/a)*b; //最好先除后乘
            //cout<<"AAA"<<s<<endl;
            if(s>sd) res=true;
            else    res=false;
        }
        if(res==true) cout<<"Lucky Bob!"<<endl;
        else   cout<<"Poor Bob!"<<endl;


    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值