05-Figure 2. Saving James bond-easy Version (25)

Source: Internet
Author: User

05-Figure 2. Saving James bond-easy Version (25) time limit MS
Memory Limit 65536 KB
Code length limit 8000 B
Procedures for the award of questions StandardAuthor 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, is 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 integers N (<=100), the number of crocodiles, and D, the maximum D Istance that James could jump. Then N 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

#include <stdio.h> #include <math.h>typedef struct {double x, y;} Coord;int Reachcenter (double distance, Coord point) {//To determine if an alligator can jump from the island to return (+ distance) * (+ distance) (>=). X*point.x + Point.y*point.y;}  int Reachbetween (double distance, Coord P1, Coord p2) {//Determine if two crocodiles can jump to return distance*distance >= (p1.x-p2.x) * (p1.x- p2.x) + (P1.Y-P2.Y) * (P1.Y-P2.Y);} int Reachbank (double distance, Coord p) {//Judging from this alligator head can jump to shore return p.x <= -50 + distance | | p.x >= 50-distance | | p. Y >= 50-distance | | P.Y <= -50 + distance;} int DFS (double distance, Coord *croc, int v, int *visited, int n) {//recursive depth-first search, find path return 1if (Reachbank (distance, Croc[v])) re Turn 1;for (int i = 0; i < n; ++i) if (!visited[i] && reachbetween (distance, croc[v], Croc[i])) {visited[i] = 1; if (DFS (distance, croc, I, visited, N)) return 1;} return 0;} int main () {//freopen ("test.txt", "R", stdin), int n;double distance;scanf ("%d%lf", &n, &distance); if (Distance & Gt;= 35) {//If you canJump directly to shore, directly return the result printf ("yes\n"); return 0;} Coord croc[102];//Save the Alligator's coordinates for (int i = 0; i < n; ++i) scanf ("%lf%lf", &croc[i].x, &croc[i].y); int visited[100] = {};//node has access token int flag = 0;//has found the path marker for (int i = 0; i < n; ++i) if (!visited[i] && reachcenter (distance, croc[i] ) {//traversal can jump from the island to the alligator visited[i] = 1;if (DFS (distance, croc, I, visited, n)) {//From the current alligator start depth first search printf ("yes\n"); flag = 1;break; }}IF (flag = = 0) printf ("no\n"); return 0;}

Title Link: http://www.patest.cn/contests/mooc-ds/05-%E5%9B%BE2

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

05-Figure 2. Saving James bond-easy Version (25)

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.