This problem is relatively simple and uses an array. In the 007 jump range, locate the alligator, and then go to the shore return yes. Otherwise no
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 is sent to a small piece by the 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 is 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 is caught by the big mouth a nd barely escaped with his extra thick boot).
Assume that's lake is a on the square one. Assume that the center of the lake was at (0,0) and the northeast corner at (50,50). The central island was a disk centered at (0,0) with the diameter of 15. A number of crocodiles is in the lake at various positions. Given the coordinates of each crocodile and the distance so James could jump, you must tell him whether or not he can ES Cape.
Input Specification:
Each input file contains the one test case. Each case starts with a line containing the positive integersN(≤100), the number of crocodiles, andd, the maximum distance that James could jump. Then nn lines follow, each Containing The (x, y) location of a Crocodile. Note that no crocodiles is staying at the same position.
Output Specification:
For each test case, the print in a line "Yes" if the James can escape, or "No" if not.
Sample Input 1:
14 2025 -15-25 288 4929 15-35 -25 2827 -29-8 -28-20 -35-25 -20-13 29-30 15-35 4012 12
Sample Output 1:
Yes
Sample Input 2:
4 13-12 1212 12-12 -1212 -12
Sample Output 2:
No
1#include <iostream>2#include <cstdio>3 using namespacestd;4 #defineMaxSize 1005 6 structCrocodiles7 {8 floatx;9 floaty;Ten }; One structCrocodiles cro[maxsize]; A - intD//007 distance to jump - intN//Number of Crocodiles the BOOLVisited[maxsize] = {false}; - - //distance less than 007 can jump distance returns true - BOOLJump (intX1,intY1,intX2,inty2) + { - if((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) <= d*d)//two point distance is less than jumping distance + return true; A return false; at } - - //returns True if 007 jumps to the shore - BOOLIssafe (intv) - { - if((cro[v].x + D >= -) || (Cro[v].y + D >= -) || (Cro[v].y-d <=- -) || (Cro[v].x-d <=- -)) in return true; - Else to return false; + } - the BOOLDFS (intV) * { $ BOOLAnswer =false;Panax NotoginsengVISITED[V] =true; - if(Issafe (V)) theAnswer =true; + Else { A for(inti =0; i < N; i++) { the if( ! Visited[i] &&Jump (CRO[V].X,CRO[V].Y,CRO[I].X,CRO[I].Y)) { +Answer =DFS (i); - if(Answer = =true) $ Break; $ } - } - } the returnanswer; - }Wuyi the //whether the first hop can jump to is return true - BOOLFirstjump (intXinty) Wu { - if(X*x + y*y <= (7.5+D) * (7.5+D)) About return true; $ Else - return false; - } - A voidsave007 () + { the BOOLAnswer =false; - for(inti =0; i < N; i++) { $ if( ! Visited[i] &&firstjump (CRO[I].X,CRO[I].Y)) { theAnswer =DFS (i); the if(Answer = =true) the Break; the } - } in if(Answer = =true) theprintf"yes\n"); the Else Aboutprintf"no\n"); the } the the + intMain () - { thescanf"%d%d",&n,&D);Bayi //if (N < (35/D-1)) {//N is at least (50-15)/d-1 the //printf ("no\n"); the //return 0; - // } - for(inti =0; i < N; i++) thescanf"%f%f",&cro[i].x,&cro[i].y); the save007 (); the return 0; the}
06-Figure 2 Saving James bond-easy Version