poj2253Frogger
/*poj2253Frogger
题意:青蛙要通过到石头到达终点 要达到终点最小步幅不能小于多少
dijkstra
*/
#include<iostream> #include<algorithm> #include<queue> #include<cmath> using namespace std; #define MAXN 1111 #define INF 100000000 pair <double,int> pii; double x[MAXN],y[MAXN],d[MAXN]; int inq[MAXN]; int n; double DIS(int i,int j) { return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); } void dijkstra() { //priority_queue<pii>pq; queue<int>q; memset(inq,0,sizeof(inq)); for(int i=0;i<n;i++)d[i]=(i==0?-INF:INF); //pq.push(make_pair(INF,)) q.push(0); while(!q.empty()) { int u=q.front(); q.pop(); inq[u]=0; for(int i=0;i<n;i++) { double len=max(DIS(u,i),d[u]);//更改判断条件 if(len<d[i]) { d[i]=len; if(!inq[i]) { inq[i]=1; q.push(i); } } } } } int main() { cout.precision(3); int cas=0; while(scanf("%d",&n)==1) { if(!n)break; for(int i=0;i<n;i++) { scanf("%lf%lf",&x[i],&y[i]); } dijkstra(); printf("Scenario #%d\nFrog Distance = ",++cas); cout<<fixed<<d[1]<<endl; printf("\n"); } }