Description
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who was sitting on another stone. He plans to visit she, but since the water was dirty and full of tourists ' sunscreen, he wants to avoid swimming and instea D reach her by jumping.
Unfortunately Fiona ' s stone is out of the his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach hers by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must is at least as long as the longest jump occuring In the sequence.
The frog distance (humans also call it minimax distance) between both stones therefore is defined as the minimum necessary Jump range possible paths between the stones.
You is given the coordinates of Freddy ' s stone, Fiona ' s stone and all other stones in the lake. Your job is to compute the frog distance between Freddy ' s and Fiona ' s stone.
The problem is to ask for all the paths, the biggest edge of the least of the one ...
Application of Dijkstra ideas, a mark ...
The code is as follows:
#include <iostream>#include<cstring>#include<cmath>#defineMax (A, b) (A>b a:b)using namespacestd;Const intinf=10e8;intN;intx[ About],y[ About];Doubleans[ About];BOOLvis[ About];voidDijkstra () {intK; DoubleMinn,len; for(intI=1; i<=n;++i) {vis[i]=0; Ans[i]=INF; } ans[1]=0; for(intI=1; i<=n;++i) {k=-1; Minn=INF; for(intj=1; j<=n;++j)if(!vis[j] && ans[j]<Minn) {Minn=Ans[j]; K=J; } if(k==-1) Break; VIS[K]=1; for(intj=1; j<=n;++j) {Len=sqrt ((Double(X[k])-x[j]) * (X[k]-x[j]) + (Double(Y[k])-y[j]) * (y[k]-y[j])); if(!vis[j] && max (Len,ans[k]) <Ans[j]) ans[j]=Max (len,ans[k]); } }}intMain () {Ios::sync_with_stdio (false); COUT.SETF (iOS::fixed); Cout.precision (3); intcas=1; for(cin>>n; n;cin>>n,++CAs) { for(intI=1; i<=n;++i) Cin>>X[i]>>Y[i]; Dijkstra (); cout<<"Scenario #"<<cas<<Endl; cout<<"Frog Distance ="<<ans[2]<<endl<<Endl; } return 0;}
View Code
Simple POJ 2253 Frogger,dijkstra.