-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.2.cpp
51 lines (45 loc) · 1.13 KB
/
6.2.cpp
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
#include <iostream>
using namespace std;
int flag=0;
void getout(int x,int y);
int distance(int i,int j,int m,int n);
void DFS(int (*crocodile)[3],int i,int n,int d);
int main(){
//初始化,录入
int n,d;
cin>>n>>d;
int crocodile[n][3];
for(int i=0;i<n;i++){
cin>>crocodile[i][0]>>crocodile[i][1];
crocodile[i][2]=0;
}
//开始深度遍历
for(int i=0;i<n;i++){
int x=crocodile[i][0];
int y=crocodile[i][1];
if(crocodile[i][2]==0&&distance(x,y,0,0)<=(7.5+d)*(7.5+d))
DFS(crocodile,i,n,d);
}
if(flag==1) cout<<"Yes";
else cout<<"No";
}
int distance(int i,int j,int m,int n){
return (i-m)*(i-m)+(j-n)*(j-n);
}
void getout(int x,int y,int d){
if(x<0) x=-x;
if(y<0) y=-y;
if((x+d>=50)||(y+d)>=50) flag=1;
}
void DFS(int (*crocodile)[3],int i,int n,int d){
crocodile[i][2]=1;
int x=crocodile[i][0];
int y=crocodile[i][1];
getout(x,y,d);
for(int m=0;m<n;m++){
int q=crocodile[m][0];
int p=crocodile[m][1];
if(distance(x,y,q,p)<=d*d&&crocodile[m][2]==0)
DFS(crocodile,m,n,d);
}
}