POJ 2253 floyd 最短路

来源:互联网 发布:淘宝怎么看权重 编辑:程序博客网 时间:2024/05/21 17:34

本想二分答案,后来发现只要修改floyd方程即可

#include <set>#include <cmath>#include <queue>#include <stack>#include <string>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef  long long LL;const double PI = acos(-1.0);template <class T> inline  T MAX(T a, T b){if (a > b) return a;return b;}template <class T> inline  T MIN(T a, T b){if (a < b) return a;return b;}const int N = 222;const int M = 11111;const LL MOD = 1000000007LL;const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};const int INF = 0x3f3f3f3f;double dist[N][N], op[N][N], d[N];int vis[N];int n;struct node{double x, y;}pt[N];double cal(double x1, double y1, double x2, double y2){return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}int main(){int cas = 1;while (scanf("%d", &n) != EOF && n){int i, j, k;double mid, l, r, t;for (i = 0; i < n; ++i){scanf("%lf%lf", &pt[i].x, &pt[i].y);}for (i = 0; i < n; ++i)for (j = 0; j < n; ++j){if (i == j) dist[i][j] = 0.0;if (i < j ) dist[i][j] = cal(pt[i].x, pt[i].y, pt[j].x, pt[j].y);if (i > j) dist[i][j] = dist[j][i];}for (k = 0; k < n; ++k)for (i = 0; i < n; ++i)for (j = i + 1; j < n; ++j){if (dist[i][j] > dist[i][k] && dist[i][j] > dist[k][j]){if (dist[i][k] < dist[k][j])dist[i][j] = dist[j][i] = dist[k][j];elsedist[i][j] = dist[j][i] = dist[i][k];}}printf("Scenario #%d\n", cas++);printf("Frog Distance = %.3lf\n\n", dist[0][1]);}return 0;}


 

原创粉丝点击