码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-04-29 01:16:19      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:lin   color   max   enter   ext   was   bond   site   happening   

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 (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( 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

我的答案,岛居然有15的直径T.T
  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <math.h>
  5 
  6 struct Crocodile {
  7     int x;
  8     int y;
  9     int Visited;
 10 };
 11 typedef struct Crocodile *Point;
 12 
 13 int ReadPoint(Point P, int N);
 14 void PrintPoint(Point P, int N);
 15 double PointDistance(Point P1, Point P2);
 16 int DFS(Point P, int N, double D, int stand);
 17 int IsUp(Point P, int stand, double D);
 18 
 19 int ReadPoint(Point P, int N)
 20 {
 21     int i;
 22     P[0].x = 0;
 23     P[0].y = 0;
 24     P[0].Visited = 0;
 25     for(i=1;i<N;i++) {
 26         scanf("%d %d\n", &P[i].x, &P[i].y);
 27         P[i].Visited = 0;
 28     }
 29     return 0;
 30 }
 31 
 32 void PrintPoint(Point P, int N)
 33 {
 34     int i;
 35     for(i=0;i<N;i++) {
 36         printf("P[%d] X:%d Y:%d\n", i, P[i].x, P[i].y);
 37     }
 38     printf("----------------------------\n");
 39 }
 40 
 41 double PointDistance(Point P1, Point P2)
 42 {
 43     return sqrt(pow((P1->x - P2->x), 2) + pow((P1->y - P2->y), 2));
 44 }
 45 
 46 int IsUp(Point P, int stand, double D)
 47 {
 48     int xlen = 50-abs(P[stand].x);
 49     int ylen = 50-abs(P[stand].y);
 50     if(stand == 1 && (xlen<=(D+7.5)
 51         || ylen<=(D+7.5))) {
 52         return 1;
 53     } else if(stand!=1 && (xlen<=D || ylen<=D)) {
 54         return 1;
 55     }
 56     return 0;           //Not
 57 }
 58 
 59 int DFS(Point P, int N, double D, int stand)
 60 {
 61     int i, ret=0, isup, island;
 62     // printf("p[%d] X:%d Y:%d ", stand, P[stand].x, P[stand].y);
 63     P[stand].Visited = 1;
 64     if(stand == 0) island = 1;
 65     isup = IsUp(P, stand, D);
 66     if(isup) {
 67         // printf("stand %d\n", stand);
 68         return 1;
 69     }
 70     for(i=1;i<N;i++) {
 71         if(!P[i].Visited && (PointDistance(&P[i], &P[stand]) <= (D+island*7.5))) {
 72             // printf("D:%lf\n", PointDistance(&P[i], &P[stand]));
 73             ret = DFS(P, N, D, i);
 74             if(ret) {
 75                 return ret;
 76             }
 77         }
 78     }
 79     return ret;
 80 }
 81 
 82 int main()
 83 {
 84     int N;
 85     double D;
 86     Point P, S;
 87 
 88     S = (Point)malloc(sizeof(struct Crocodile));
 89     S->x = 0;
 90     S->y = 0;
 91 
 92     scanf("%d %lf\n", &N, &D);
 93     N++;                                            //N = N + 1;
 94     P = (Point)malloc(sizeof(struct Crocodile)*N);
 95     ReadPoint(P, N);
 96     // PrintPoint(P, N);
 97     if(DFS(P, N, D, 0))
 98         printf("Yes\n");
 99     else
100         printf("No\n");
101 
102     return 0;
103 }

 

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

标签:lin   color   max   enter   ext   was   bond   site   happening   

原文地址:https://www.cnblogs.com/ch122633/p/8970046.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!