• 7-10 Saving James Bond


    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 (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( 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
    这道题的数据很水,一开始误认为半径是15都能对。
    图类题目,起始在一个直径15(半径7.5)的小岛上,问是否能跳到岸边,湖里有很多鳄鱼,给出最大跳跃距离,可以跳到范围内的鳄鱼身上。起点是(0,0),只要能到达一个点其横坐标或者纵坐标与边界距离在最大条约距离范围内即可上岸。
    bfs过一遍即可。
    代码:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    struct crocodile {
        int x,y;
    }c[100],q[100],temp;
    int n,d,head,tail,flag;
    int check(int x,int y) {
        x = abs(x);
        y = abs(y);
        return x + d >= 50 || y + d >= 50;
    }
    int main() {
        scanf("%d%d",&n,&d);
        for(int i = 0;i < n;i ++) {
            scanf("%d%d",&c[i].x,&c[i].y);
            if(sqrt(pow(c[i].x,2) + pow(c[i].y,2)) - 7.5 <= d) {
                q[tail ++] = c[i];
                i --,n --;
            }
        }
        while(head < tail) {
            temp = q[head ++];
            if(check(temp.x,temp.y)) {
                flag = 1;
                break;
            }
            for(int i = 0;i < n;i ++) {
                if(sqrt(pow(c[i].x - temp.x,2) + pow(c[i].y - temp.y,2)) <= d) {
                    q[tail ++] = c[i];
                    c[i --] = c[-- n];
                } 
            }
        }
        puts(flag ? "Yes" : "No");
        return 0;
    }
  • 相关阅读:
    延时调用的php代码
    mysql 官网下载太慢了,来这里!!!
    解决react-native 运行报错:Entry, ":CFBundleIdentifier", Does Not Exist
    mongodb增删改查常用命令总结
    Linux 查看文件内容(8)
    Linux mv命令(7)
    Linux文件拷贝(6)
    Linux 创建与删除(5)
    Linux cd命令(4)
    ls 命令通配符(3)
  • 原文地址:https://www.cnblogs.com/8023spz/p/12264030.html
Copyright © 2020-2023  润新知