7-12 拯救007

在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)
设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为圆心、直径15米的圆。给定池中分布的鳄鱼的坐标、以及007一次能跳跃的最大距离,你需要告诉他是否有可能逃出生天。
输入格式:
首先第一行给出两个正整数:鳄鱼数量 N(≤100)和007一次能跳跃的最大距离 D。随后 N 行,每行给出一条鳄鱼的 (x,y) 坐标。注意:不会有两条鳄鱼待在同一个点上。
输出格式:
如果007有可能逃脱,就在一行中输出"Yes",否则输出"No"。
输入样例 1:
14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12

输出样例 1:
Yes

输入样例 2:
4 13
-12 12
12 12
-12 -12
12 -12

输出样例 2:
No

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
struct lala
{
    int x,y;
    double dis;
} p[102];
int vis[102],n,d;
double cal(int x,int y)
{
    return sqrt(x*x+y*y)-15;//到陆地边缘的距离
}
int cha(int x1,int y1,int x2,int y2)
{
    if(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))>d)
        return 0;
    return 1;
}
void bfs()
{
    int i;
    queue<lala> q;
    for(i=0; i<n; i++)
        if(p[i].dis<=d)
        {
            q.push(p[i]);
            vis[i]=1;
        }
    while(!q.empty())
    {
        struct lala node=q.front();
        if(node.x+d>=50||node.x-d<=-50||node.y+d>=50||node.y-d<=-50)
        {
            cout<<"Yes"<<endl;
            return ;
        }
        q.pop();
        for(i=0; i<n; i++)
            if(!vis[i]&&cha(node.x,node.y,p[i].x,p[i].y))//???????
            {
                q.push(p[i]);
                vis[i]=1;
            }
    }
    cout<<"No"<<endl;
}
int main()
{
    cin>>n>>d;
    int i;
    for(i=0; i<n; i++)
        cin>>p[i].x>>p[i].y,p[i].dis=cal(p[i].x,p[i].y);
    bfs();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43589396/article/details/88602315
今日推荐