/
hw5-2.c
99 lines (82 loc) · 1.43 KB
/
hw5-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <math.h>
#define DIS 7.5
int visited[100];
int firstjump=1;
int answer=0;
int num,step;
typedef struct position{
double x;
double y;
}pos;
// measure the distance between tow points
double distance(pos p1,pos p2){
// printf("%lf\n",sqrt((pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2))));
// printf("%lf",sqrt((pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2))));
return sqrt((pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2)));
}
int IsSafe(pos p){
if(50-abs(p.x)<=step || (50-abs(p.y))<=step)
return 1;
else
return 0;
}
int DFS(pos p[],int i){
visited[i]=1;
int j=0;
if(IsSafe(p[i])==1)
answer=1;
else {
for(j=0;j<num;j++){
// printf("give a judge\n");
if(visited[j]==0 && distance(p[i],p[j])<=step){
answer=DFS(p,j);
if(answer==1) break;
}
}
}
return answer;
}
void save(pos p[]){
int j;
pos zero;
zero.x=0;
zero.y=0;
if(step+DIS>=50){
answer=1;
} else {
for(j=0;j<num;j++){
// printf("The distance is :%lf \n",distance(zero,p[j]));
if(visited[j]==0 && distance(zero,p[j]) <= DIS+step){
answer=DFS(p,j);
if(answer==1)
break;
}
}
}
if(answer==1)
printf("Yes");
else
printf("No");
}
int main(){
pos p[100];
scanf("%d %d",&num,&step);
int i;
for(i=0;i<num;i++){
visited[i]=0;
scanf("%lf %lf",&p[i].x,&p[i].y);
}
/*
pos zero;
zero.x=40;
zero.y=40;
printf("%d",IsSafe(zero));
*/
save(p);
/*
for(i=0;i<num;i++){
printf("%d ",visited[i]);
}
*/
}