标签:mem end return const add code sizeof algorithm frog
#include<math.h> #include<iomanip> //setprecision头文件 #include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<queue> using namespace std; const int N=1e6,INF=0x3f3f3f3f; bool st[N]; double dist[N]; int n,m; int h[N],e[N],ne[N],idx; double w[N]; struct inp{ int x; int y; }p[N]; void add(int a,int b,double c) { e[idx]=b; w[idx]=c; ne[idx]=h[a]; h[a]=idx++; } void spfa() { for(int i=1;i<=n;i++) dist[i]=INF; memset(st,0,sizeof st); queue<int>q; q.push(1); dist[1]=0; st[1]=1; while(q.size()) { int t=q.front(); q.pop(); st[t]=0; for(int i=h[t];i!=-1;i=ne[i]) { int j=e[i]; if(dist[j]>max(dist[t],w[i])) { dist[j]=max(dist[t],w[i]); if(!st[j]) { st[j]=1; q.push(j); } } } } } int main() { int cas=1; while(cin>>n&&n) { idx=0; memset(h,-1,sizeof h); for(int i=1;i<=n;i++) { cin>>p[i].x>>p[i].y; for(int j=1;j<i;j++) { double s=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)); add(i,j,s); add(j,i,s); } } spfa(); cout<<"Scenario #"<<cas++<<endl; cout<<"Frog Distance = "<<fixed<<setprecision(3)<<dist[2]<<endl<<endl; } return 0; }
标签:mem end return const add code sizeof algorithm frog
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12239872.html