PAT Saving James Bond - Easy Version

Saving James Bond - Easy Version

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.

funny problem 继续考察图的遍历   我用了DFS  每个鳄鱼还有小岛都为顶点  注意  第一次从小岛跳出的时候还要加上小岛的半径7.5

下面给出AC代码  每天AC一道题 生活好滋味

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <stdlib.h>
 4
 5 int flag[150],flag1=0;
 6 int D,N;
 7 float r,dis;
 8
 9 typedef struct
10 {
11     int x;
12     int y;
13 }crocodile;
14 crocodile c[150];
15 void DFS(int i)
16 {
17     r=D;
18     flag[i]=1;
19     if((50-abs(c[i].x))<=r ||(50-abs(c[i].y))<=r)
20     {
21         printf("Yes\n");
22         flag1=1;
23         r=-1;
24         return;
25     }
26     int j;
27
28     for(j=1;j<=N;j++)
29     {
30
31         dis=sqrt((c[j].x-c[i].x)*(c[j].x-c[i].x)+(c[j].y-c[i].y)*(c[j].y-c[i].y));
32         if(dis<=r && flag[j]!=1)
33         {
34             DFS(j);
35         }
36     }
37 }
38 main()
39 {
40     int i,j;
41     scanf("%d%d",&N,&D);
42
43     c[0].x=c[0].y=0;
44     for(i=1;i<=N;i++)
45         scanf("%d%d",&c[i].x,&c[i].y);
46     r=15.0/2+D;
47     i=0;
48     for(j=1;j<=N;j++)
49     {
50         dis=sqrt((c[j].x-c[i].x)*(c[j].x-c[i].x)+(c[j].y-c[i].y)*(c[j].y-c[i].y));
51         if(dis<=r && flag[j]!=1)
52         {
53             DFS(j);
54             r=15.0/2+D;
55         }
56     }
57     if(flag1==0)
58         printf("No\n");
59 }
时间: 2024-08-02 09:45:57

PAT Saving James Bond - Easy Version的相关文章

05-图2. Saving James Bond - Easy Version (25)

05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 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, was capture

05-2. Saving James Bond - Easy Version (25)

05-2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 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, was captured

pat05-图2. Saving James Bond - Easy Version (25)

05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 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, was capture

Saving James Bond - Easy Version (MOOC)

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

05-2. Saving James Bond - Easy Version (PAT) - 图的遍历问题

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 crocodile

Saving James Bond - Easy Version

本博客的代码的思想和图片参考:好大学慕课浙江大学陈越老师.何钦铭老师的<数据结构> Question: 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 p

PTA 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 crocodile

06-图2 Saving James Bond - Easy Version

这题比较简单,用了数组.在007跳跃范围内,找到鳄鱼,依次直到岸边 return yes.否则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 was sent to a small piece of

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 crocodile