标签:sqrt string ops second ref problem term cal nim
https://vjudge.net/problem/POJ-2253
Input
Output
Sample Input
2 0 0 3 4 3 17 4 19 4 18 5 0
Sample Output
Scenario #1 Frog Distance = 5.000 Scenario #2 Frog Distance = 1.414
1 //#include<bits/stdc++.h> 2 #include<iostream> 3 #include<stdio.h> 4 #include<string.h> 5 #include<algorithm> 6 #include<cmath> 7 #include<vector> 8 #include<queue> 9 #define maxn 210 10 #define ms(x,n) memset(x,n,sizeof x); 11 const int inf=0x3f3f3f3f; 12 using namespace std; 13 int n; 14 double d[maxn],cost[maxn][maxn]; 15 bool vis[maxn]; 16 struct node 17 { 18 int x,y; 19 node(int xx,int yy){x=xx,y=yy;} 20 }; 21 vector<node> v; 22 double dis(double x1,double y1,double x2,double y2) 23 { 24 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 25 } 26 typedef pair<double,int> p; 27 28 void dij(int s) 29 { 30 fill_n(d,maxn,inf); 31 ms(vis,0); 32 priority_queue<p,vector<p>,greater<p> >q; 33 q.push(p(d[s]=0,s)); 34 while(!q.empty()) 35 { 36 p cur=q.top(); 37 q.pop(); 38 int i=cur.second; 39 if(vis[i])continue; 40 vis[i]=1; 41 for(int j=0;j<n;j++) 42 { 43 if(max(d[i],cost[i][j])<d[j]) 44 {d[j]=max(d[i],cost[i][j]); 45 q.push(p(d[j],j)); 46 } 47 } 48 } 49 } 50 int main() 51 { 52 int t=0; 53 while(~scanf("%d",&n),n) 54 { 55 int x,y; 56 v.clear(); 57 for(int i=1;i<=n;i++) 58 { 59 scanf("%d%d",&x,&y); 60 v.push_back(node(x,y)); 61 } 62 fill_n(cost[0],maxn*maxn,inf); 63 for(int i=0;i<n;i++) 64 for(int j=i+1;j<n;j++) 65 cost[i][j]=cost[j][i]=dis(v[i].x,v[i].y,v[j].x,v[j].y); 66 dij(0); 67 if(t)cout<<endl; 68 // printf("Scenario #%d\nFrog Distance = %.3f\n",t++,d[1]); 69 printf("Scenario #%d\nFrog Distance = %.3f\n", ++t, d[1]); 70 71 } 72 return 0; 73 }
标签:sqrt string ops second ref problem term cal nim
原文地址:https://www.cnblogs.com/zuiaimiusi/p/10777147.html