POJ 2253 Frogger
A frog finds another frog, but he can jump to the position of the target frog through other stones. when inputting data, the first group of data is the position of the first frog, the second group is the position of the target frog, and the other is the position of the stone.
Idea: the dijkstra algorithm has a small deformation, and the practice is the same.
Tips: the dual-precision floating point output on POJ turned out to be % f. I 've always been wrong, or the compilation is wrong, so it's annoying!
AC code:
#include
#include
#includeusing namespace std;#define maxn 100000000#define N 212struct p{ int x,y;};p point[N];int n;double d[N];double dis(p a,p b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void dijkstra(){ double minn; int i,j,vis[N],v; for(i=1;i<=n;i++) { vis[i]=0; d[i]=maxn; } v=1; d[1]=0; for(i=1;i<=n;i++) { minn=maxn; for(j=1;j<=n;j++) { if(!vis[j]&&d[j]
max(d[v],dis(point[v],point[j])))d[j]=max(d[v],dis(point[v],point[j])); }}int main(){ int cnt=1; while(scanf("%d",&n)!=EOF) { if(n==0)break; for(int i=1;i<=n;i++) scanf("%d %d",&point[i].x,&point[i].y); dijkstra(); printf("Scenario #%d\nFrog Distance = %.3f\n",cnt++,d[2]); printf("\n"); } return 0;}