zoukankan      html  css  js  c++  java
  • pat05-图2. Saving James Bond

    05-图2. Saving James Bond - Easy Version (25)

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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
    

    提交代码

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<queue>
     6 #include<vector>
     7 #include<map>
     8 #include<cmath>
     9 #include<string>
    10 using namespace std;
    11 struct point{
    12     int x,y;
    13     double dis;
    14     bool vis;
    15     point(){
    16         vis=false;
    17     }
    18 };
    19 double getdis(int x1,int y1,int x2,int y2){
    20     int dx=x1-x2;
    21     int dy=y1-y2;
    22     return sqrt(dx*dx+dy*dy);
    23 }
    24 int abs(int a){
    25     if(a<0){
    26         a=-a;
    27     }
    28     return a;
    29 }
    30 point cro[105];
    31 int main(){
    32     //freopen("D:\INPUT.txt","r",stdin);
    33     int n,J;
    34     int i;
    35     queue<int> q;
    36     scanf("%d %d",&n,&J);
    37     point *cro=new point[n];
    38     for(i=0;i<n;i++){
    39         scanf("%d %d",&cro[i].x,&cro[i].y);
    40         cro[i].dis=getdis(0,0,cro[i].x,cro[i].y);
    41     }
    42     if(7.5+J>=50){
    43         printf("Yes
    ");
    44         return 0;
    45     }
    46     for(i=0;i<n;i++){
    47         if(cro[i].dis<=7.5){
    48             cro[i].vis=true;//无效点
    49         }
    50         else if(cro[i].dis<=7.5+J){//在弹跳范围内,收集
    51             q.push(i);
    52             cro[i].vis=true;
    53         }
    54     }
    55     int curnum,x,y;
    56     while(!q.empty()){
    57         curnum=q.front();
    58         q.pop();
    59         x=cro[curnum].x;
    60         y=cro[curnum].y;
    61         if(abs(x)+J>=50||abs(y)+J>=50){//可以到达岸边
    62             printf("Yes
    ");
    63             return 0;
    64         }
    65         for(i=0;i<n;i++){
    66             if(!cro[i].vis){
    67                 cro[i].dis=getdis(x,y,cro[i].x,cro[i].y);
    68                 if(cro[i].dis<=J){
    69                     q.push(i);
    70                     cro[i].vis=true;
    71                 }
    72             }
    73         }
    74     }
    75     printf("No
    ");
    76     return 0;
    77 }
  • 相关阅读:
    停止与暂停线程
    flume日志收集框架
    mysql数据库索引
    junit
    freemarker
    python脚本
    java多线程编程核心技术学习-1
    spring 网站
    [MongoDB]学习笔记--Linux 安装和运行MongoDB
    [Spring MVC]学习笔记--form表单标签的使用
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4742664.html
Copyright © 2011-2022 走看看