码迷,mamicode.com
首页 > 其他好文 > 详细

uva 10803 Thunder Mountain (floyd)

时间:2015-07-24 18:38:13      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

uva 10803 Thunder Mountain

题目大意:给出n个点的坐标,要求n个点每两点之间的最大距离。若这n个点,有不连通的地方,则输出Send Kurdy。

解题思路:Floyd。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int N = 105;
const int INF = 0x3f3f3f3f;
int n;
double G[N][N];
double X[N], Y[N];
double dis(int x, int y) {
    return ((X[x] - X[y]) * (X[x] - X[y]) + (Y[x] - Y[y]) * (Y[x] - Y[y]));
}
void floyd() {
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (G[i][j] > G[i][k] + G[k][j]) {
                    G[i][j] = G[i][k] + G[k][j];
                }   
            }   
        }
    }
}
int main() {
    int T, Case = 1;
    scanf("%d", &T);
    while (T--) {
        printf("Case #%d:\n", Case++);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = INF;  
            }   
        }
        scanf("%d", &n);
        int a, b;
        for (int i = 0; i < n; i++) {
            scanf("%lf %lf", &X[i], &Y[i]); 
        }       
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    G[i][j] = INF;
                    continue;
                }
                G[i][j] = sqrt(dis(i, j));
                if (G[i][j] > 10.0) G[i][j] = INF;
            }   
        }
        floyd();
        double ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (G[i][j] > ans) ans = G[i][j];
            }   
        }
        if (INF - ans < 1e-9) printf("Send Kurdy\n");
        else printf("%.4lf\n", ans);
        printf("\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

uva 10803 Thunder Mountain (floyd)

标签:

原文地址:http://blog.csdn.net/llx523113241/article/details/47041271

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!