POJ 2253 最短路

#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 200 + 5;
int n, kase;
double dis[maxn][maxn], X[maxn], Y[maxn];
void floyd()
{
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (dis[i][j] > max(dis[i][k], dis[k][j]))
					dis[i][j] = max(dis[i][k], dis[k][j]);
}
int main(int argc, char const *argv[])
{
	while (~scanf("%d", &n) && n)
	{
		memset(X, 0, sizeof(X));
		memset(Y, 0, sizeof(Y));
		memset(dis, 0, sizeof(dis));
		for (int i = 1; i <= n; i++)
			scanf("%lf%lf", &X[i], &Y[i]);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
			{
				double Tx = X[i] - X[j];
				double Ty = Y[i] - Y[j];
				dis[i][j] = dis[j][j] = sqrt(Tx * Tx + Ty * Ty);
			}
		floyd();
		printf("Scenario #%d\nFrog Distance = %.3lf\n\n", ++kase, dis[1][2]);
	}
	return 0;
}


水题一道。

你可能感兴趣的:(POJ 2253 最短路)