Saving James Bond-easy version (MOOC)

Source: Internet
Author: User
06-Figure 2 Saving James Bond-easy version (25 points)

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 got Med 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 cocould 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 cocould 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 coshould 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 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

Overall Program Framework:

DFS Algorithm


Int DFS (vertex v) {visited [v] = true; If (issafe (V) Answer = yes; else {for (W of each adjacent vertex of V) if (! Visited [w]) {answer = DFS (w); If (answer = Yes) Break ;}} return answer;

 

Code:

# Include <cstdio> # include <cmath> using namespace STD; struct node {int X, Y;} G [110]; int N, D; int vis [110]; int ans = 0; bool firstjump (int I) {int p1 = POW (G [I]. x, 2); int P2 = POW (G [I]. y, 2); int r = (D + 7.5) * (D + 7.5); If (P1 + p2 <= r) return true; return false ;} bool jump (int v, int I) {int p1 = POW (G [v]. x-G [I]. x, 2); int P2 = POW (G [v]. y-G [I]. y, 2); If (P1 + p2 <= D * d) return true; else return false;} bool issave (INT v) {If (G [v]. X + 50 <= D | 50-g [v]. x <= d | 50 + G [v]. Y <= d | 50-g [v]. Y <= d) return true; return false;} // DFS 1. traverse all nodes and find the nodes that can jump to DFS 2. if the node can jump ashore, return result 1. int DFS (INT v) {vis [v] = 1; if (issave (V) return 1; for (INT I = 0; I <n; I ++) {If (! Vis [I] & jump (V, I) {ans = DFS (I); If (ANS) break; // if it is changed to If (! Ans) return ans; error in sample 2. Because the loop is not over, return} return ans;} int main () {scanf ("% d", & N, & D); getchar (); for (INT I = 0; I <n; I ++) {scanf ("% d", & G [I]. x, & G [I]. y); // struct structure storage X, Y coordinate getchar () ;}for (INT I = 0; I <n; I ++) {If (firstjump (I) &&! Vis [I]) {// first, determine whether the first step can jump out. The Node ans = DFS (I); If (ANS) Break ;}} if (ANS) has not been traversed) printf ("yes"); else printf ("no"); Return 0 ;}

 

Saving James Bond-easy version (MOOC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.