标签:sam ace exec alt pat center rmi ops source
题目链接:http://poj.org/problem?id=2253
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 49409 | Accepted: 15729 |
Description
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
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++) 13 #define ms(a,b) memset((a),(b),sizeof((a))) 14 using namespace std; 15 typedef long long LL; 16 const double EPS = 1e-8; 17 const int INF = 2e9; 18 const LL LNF = 9e18; 19 const int MOD = 1e9+7; 20 const int MAXN = 1e3+10; 21 22 int n; 23 24 struct edge 25 { 26 double w; 27 int to, next; 28 }edge[MAXN*MAXN]; 29 int cnt, head[MAXN]; 30 31 void addedge(int u, int v, double w) 32 { 33 edge[cnt].to = v; 34 edge[cnt].w = w; 35 edge[cnt].next = head[u]; 36 head[u] = cnt++; 37 } 38 39 void init() 40 { 41 cnt = 0; 42 memset(head, -1, sizeof(head)); 43 } 44 45 double dis[MAXN]; 46 bool vis[MAXN]; 47 void dijkstra(int st) 48 { 49 memset(vis, 0, sizeof(vis)); 50 for(int i = 1; i<=n; i++) 51 dis[i] = (i==st?0:INF); 52 53 for(int i = 1; i<=n; i++) 54 { 55 int k; 56 double minn = INF; 57 for(int j = 1; j<=n; j++) 58 if(!vis[j] && dis[j]<minn) 59 minn = dis[k=j]; 60 61 vis[k] = 1; 62 for(int j = head[k]; j!=-1; j = edge[j].next) 63 if(!vis[edge[j].to]) 64 dis[edge[j].to] = min(dis[edge[j].to], max(dis[k], edge[j].w) ); 65 } 66 } 67 68 int x[MAXN], y[MAXN]; 69 int main() 70 { 71 int kase = 0; 72 while(scanf("%d", &n) && n) 73 { 74 init(); 75 for(int i = 1; i<=n; i++) 76 scanf("%d%d", &x[i], &y[i]); 77 for(int i = 1; i<=n; i++) 78 for(int j = 1; j<=n; j++) 79 addedge(i, j, sqrt( (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) ); 80 81 dijkstra(1); 82 printf("Scenario #%d\n", ++kase); 83 printf("Frog Distance = %.3f\n\n", dis[2]); 84 } 85 }
标签:sam ace exec alt pat center rmi ops source
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7595633.html