Test instructions
The speed of the mouse to V and the mouse at the longest time outside the hole m, the ground n points coordinates, asked if the mouse can be from hole 1 to hole 2, you can ask for a minimum number of hops.
Analysis:
Bare shortest, pay attention to accuracy.
Code:
POJ 2627//sep9#include <iostream> #include <queue>using namespace std;const int Maxn=1024;const int maxm= 2000024;int n,e,head[maxn];int d[maxn];int inq[maxn];struct point{__int64 x, y;} Pnt[1024];__int64 v,m;struct edge{int v,w,nxt;} EDGE[MAXM]; void Addedge (int u,int v,int W) {edge[e].v=v;edge[e].w=w;edge[e].nxt=head[u];head[u]=e++;edge[e].v=u;edge[e].w=w; edge[e].nxt=head[v];head[v]=e++;} Queue<int> q;void SPFA () {for (int i=0;i<n;++i) D[i]=int_max;memset (inq,0,sizeof (INQ));d [0]=0; Q.push (0); Inq[0]=1;while (! Q.empty ()) {int U=q.front (); Q.pop (); inq[u]=0;for (int i=head[u];i!=-1;i=edge[i].nxt) {int v=edge[i].v,w=edge[i].w;if (D[u]+w<d[v]) {D[v]=d[u] +w;if (!inq[v]) {inq[v]=1; Q.push (v);}}}} int main () {E=0;memset (head,-1,sizeof (head)), scanf ("%i64d%i64d", &v,&m), M*=60;double x,y;n=0;while (scanf (" %lf%lf ", &x,&y) ==2) {pnt[n].x= (__int64) (x*1000.0+1e-6);p nt[n].y= (__int64) (y*1000.0+1e-6); ++n;} int I,j;for (i=0;i<n;++i) for (j=i+1;j<n;++j) {__int64 dis= (pnt[i].x-pnt[j].x) * (pnt[i].x-pnt[j].x) + (PNT[I].Y-PNT[J].Y) * (PNT[I].Y-PNT[J].Y); if (dis<=v*m*v*m*1000000) Addedge (i,j,1);} SPFA (); if (D[1]==int_max) printf ("No."); elseprintf ("Yes, visiting%d other holes.", d[1]-1); return 0;}
POJ 2627 Gopher and Hawks shortest circuit