-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10610 - Gopher and Hawks.cpp
121 lines (101 loc) · 2.19 KB
/
10610 - Gopher and Hawks.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<sstream>
#include<map>
#include<utility>
using namespace std;
#define sf scanf
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf printf
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define mp make_pair
#define pb push_back
#define inf (1<<30)-2
#define sz 1005
typedef long long int ll;
//int xx[] = {0, 1, 0, -1, -1, 1, 1, -1 }; //4 & 8 move
//int yy[] = {1, 0, -1, 0, 1, 1, -1,-1 };
/*------------------------------------------------------------*/
struct node
{
int indx;
double x,y;
node () { }
node(int a,double b,double c)
{
indx=a;
x=b;
y=c;
}
};
node data[sz];
int dist[sz];
int nd;
double calc_dist(int i,int j)
{
return sqrt(((data[i].x-data[j].x)*(data[i].x-data[j].x))+((data[i].y-data[j].y)*(data[i].y-data[j].y)));
}
void bfs(double m)
{
clr(dist,-1);
queue<node>q;
q.push(data[0]);
dist[0]=0;
while(!q.empty())
{
node tmp=q.front();
q.pop();
for(int i=0; i<nd; i++)
{
if(dist[i]==-1 && m>=calc_dist(tmp.indx,i))
{
q.push(data[i]);
dist[i]=dist[tmp.indx]+1;
}
}
}
// for(int i=0; i<4; i++)
// pf("%d ",dist[i]);
// pf("\n");
}
int main()
{
//#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
//#endif
int tst,i,k,j,l,cs;
int v,m;
char ar[50];
while(sf2(v,m)==2)
{
scanf("\n");
if(!v && !m)
return 0;
l=0;
double mmrs=v*60.0*m;
while(gets(ar))
{
if(strlen(ar)==0)
break;
sscanf(ar,"%lf %lf",&data[l].x,&data[l].y);
// pf("%d %lf %lf\n",l,data[l].x,data[l].y);
data[l].indx=l;
l++;
nd=l;
}
bfs(mmrs);
if(dist[1]==-1)
pf("No.\n");
else pf("Yes, visiting %d other holes.\n",dist[1]-1);
}
return 0;
}