I use the following procedure:
1. mark all (u,v) such that gopher can go from u to v in m minutes with its speed v m/sec.
2.Then call bfs.
But get wrong ans. Is the procedure wrong?
Moderator: Board moderators

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#define INF 99999
using namespace std;
class point
{
public:
double x,y;
};
point P[1010];
char s[100];
int count;//number of points
double con;//condition to be satisfied
bool used[1010];//used marker
int d[3010];//memo
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int search(int p,bool used[])
{
if(p==1)
{
d[p]=1;
return 1;
}
if(d[p]<INF)
{
return d[p];
}
register int min=INF,i,x;
for(i=0;i<count;i++)
{
if(!used[i] && dis(P[p],P[i])<=con)
{
used[i]=true;
x=1+search(i,used);
if(x<min)
{
min=x;
}
used[i]=false;
}
}
d[p]=min;
return min;
}
int main(void)
{
register double v,t;
register char dummy[10];
while(1)
{
scanf("%lf%lf",&v,&t);
if(v==0 && t==0)
{
break;
}
else
{
con=v*t*60.0;
}
gets(dummy);
count=0;
while(1)
{
gets(s);
if(strcmp(s,"")==0)
{
break;
}
sscanf(s,"%lf%lf",&P[count].x,&P[count].y);
d[count]=INF;
used[count]=false;
count++;
}
used[0]=true;
register int x=search(0,used);
if(x<INF)
{
printf("Yes, visiting %d other holes.\n",x-2);
}
else
{
printf("no.\n");
}
}
return 0;
}
Users browsing this forum: No registered users and 0 guests