• 图2 Saving James Bond


    题目:https://pintia.cn/problem-sets/1268384564738605056/problems/1281571555116650496

    This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).

    Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether or not he can escape.

    Input Specification:

    Each input file contains one test case. Each case starts with a line containing two positive integers N (100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y) location of a crocodile. Note that no two crocodiles are staying at the same position.

    Output Specification:

    For each test case, print in a line "Yes" if James can escape, or "No" if not.

    Sample Input 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
    
     

    Sample Output 1:

    Yes
    
     

    Sample Input 2:

    4 13
    -12 12
    12 12
    -12 -12
    12 -12
    
     

    Sample Output 2:

    No


    题解:https://blog.csdn.net/tuzigg123/article/details/46893747
    代码:

        /*2015.7.15*/
        #include <iostream>
        #include <vector>
        #include <math.h>
        #include <queue>
        #include <fstream>
        using namespace std;
         
        //ifstream fin("case1.txt");
        //#define cin fin
         
        struct point{
            float x;
            float y;
            bool canEscape;
        };
        int main(){
            int N,D;
            cin>>N>>D;
            vector<point> vexs(N);
            vector<vector<bool> > edges(N,vector<bool>(N,false));
         
            for(int i=0;i<N;i++){//鳄鱼序号为0到N-1
                cin>>vexs[i].x>>vexs[i].y;
                if(fabs(vexs[i].x)+D>=50||fabs(vexs[i].y)+D>=50){
                    vexs[i].canEscape=true;  //标记能一步跳到岸边的点
                }else
                    vexs[i].canEscape=false;
            }
            for(int i=0;i<N;i++){
                for(int j=i+1;j<N;j++){
                    float dx=vexs[i].x-vexs[j].x;
                    float dy=vexs[j].y-vexs[j].y;
                    if(dx*dx+dy*dy<=D*D){//标记能够两两连通的点
                        edges[i][j]=true;
                        edges[j][i]=true;
                    }
                }
            }
            //BFS
            queue<int> cur,next;
            vector<int> visited(N,false);
         
            for(int i=0;i<N;i++){
                if(vexs[i].x*vexs[i].x+vexs[i].y*vexs[i].y<=(D+7.5)*(D+7.5)){
                    cur.push(i);//能够从湖中小岛跳到的点入队
                    visited[i]=true;
                }
            }
            
            while(!cur.empty()){
                while(!cur.empty()){
                    int root=cur.front();
                    cur.pop();
                    if(vexs[root].canEscape){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                    for(int i=0;i<N;i++){
                        if(edges[root][i]&&!visited[i]){
                            next.push(i);
                            visited[i]=true;
                        }
                    }
                }
                swap(cur,next);
            }
            cout<<"No"<<endl;
            return 0;
        }



  • 相关阅读:
    使用NPOI导出Excel 并设置Excel样式(合并单元格、行高、宽度、字体、边框、位置)...
    DevExpress GridView 单元格进度条
    c# groupBox 带标题边框,标题居中,重写控件
    COCO数据集下载断断续续后unzip无法解压
    SSD_论文+代码(pytorch)
    开始机器学习
    收藏 —— KVM网络虚拟化
    收藏 —— 教你阅读Python开源项目
    收藏 —— 活动目录讲解
    系统计划 Cron作业 为什么/etc/crontab /etc/cron.d /etc/cron.* 那么多的定义方式????
  • 原文地址:https://www.cnblogs.com/simon-chou/p/13619979.html
Copyright © 2020-2023  润新知