zoukankan      html  css  js  c++  java
  • Saving James Bond

    06-图2 Saving James Bond - Easy Version(25 分)

    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<iostream>
     2 #include<math.h> 
     3 #include<vector>
     4 using namespace std;
     5 #define MaxN 101
     6 int flag=0;
     7 vector<int> visited(MaxN,0);
     8 struct node{
     9 int x;
    10 int y;
    11 };
    12 struct Gnode{
    13 int N;
    14 int D;
    15 node G[MaxN];
    16 };
    17 using Graph=Gnode*;
    18 Graph buildGraph(){
    19 int N,D,x,y;
    20 cin>>N>>D;
    21 Graph gra=new Gnode();
    22 gra->N=N; gra->D=D;
    23 gra->G[0].x=0; gra->G[0].y=0;
    24 for(int i=1;i<=gra->N;i++){
    25 cin>>x>>y; 
    26 gra->G[i].x=x; gra->G[i].y=y;
    27 }
    28 return gra;
    29 }
    30 double distance(node n1,node n2)
    31 {
    32 return sqrt((n1.x-n2.x)*(n1.x-n2.x)+(n1.y-n2.y)*(n1.y-n2.y));
    33 }
    34 int finish(Graph gra,int v){
    35 if(gra->G[v].x>=50-gra->D)
    36 {flag=1;return 1;}
    37 if(gra->G[v].x<=-50+gra->D)
    38 {flag=1;return 1;}
    39 if(gra->G[v].y>=50-gra->D)
    40 {flag=1;return 1;}
    41 if(gra->G[v].y<=-50+gra->D)
    42 {flag=1;return 1;}
    43 return 0;
    44 }
    45 void DFS(Graph gra,int v){
    46 visited[v]=1;
    47 if(finish(gra,v))
    48     return;
    49 for(int i=1;i<=gra->N;i++)
    50 if(visited[i]!=1&&distance(gra->G[i],gra->G[v])<=gra->D)
    51 DFS(gra,i);
    52 } 
    53 void Givenanswer(Graph gra){
    54 int v;
    55 if(gra->D>=50)
    56 flag=1;
    57 for(v=1;v<=gra->N;v++){
    58 if(flag==0){  //cout<<distance(gra->G[v],gra->G[0])-7.5<<endl;
    59 if(visited[v]!=1&&distance(gra->G[v],gra->G[0])-15<=gra->D)
    60 {  DFS(gra,v);}
    61 }
    62 
    63 }
    64 if(flag==1) cout<<"Yes"<<endl;
    65 else cout<<"No"<<endl;
    66 }
    67 int main()
    68 {
    69 Graph gra=buildGraph(); 
    70 Givenanswer(gra);
    71 return 0;
    72 }
    View Code
  • 相关阅读:
    WebView用法与JS交互(2) 响应webview中的图片点击事件
    出栈序列(栈和队列)
    Log Files
    Mr. Frog’s Game
    Comparison of Android versions
    Linearization of the kernel functions in SVM
    Game of Nuts
    Easy Summation
    Automatic Judge
    Coprime Sequence
  • 原文地址:https://www.cnblogs.com/A-Little-Nut/p/8056106.html
Copyright © 2011-2022 走看看