POJ2502 Subway flody

来源:互联网 发布:mac虚拟机怎么用 编辑:程序博客网 时间:2024/05/16 10:37
/*floyd*/#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>#include <iomanip>using namespace std;const int maxn = 205;const int inf = 1 << 30;double g[maxn][maxn];int c;struct node {double x, y;};node s[maxn];double walk(int i, int j){double len = sqrt((s[i].x - s[j].x) * (s[i].x - s[j].x) + (s[i].y - s[j].y) * (s[i].y - s[j].y));return 60 * len / 10000;}double subway(int i, int j){double len = sqrt((s[i].x - s[j].x) * (s[i].x - s[j].x) + (s[i].y - s[j].y) * (s[i].y - s[j].y));return 60 * len / 40000;}void floyd(){for (int k = 1; k <= c; ++k) {for (int i = 1; i <= c; ++i) {for (int j = 1; j <= c; ++j) {g[i][j] = min(g[i][j], g[i][k] + g[k][j]);}}}return;}int main(){while (cin >> s[1].x >> s[1].y >> s[2].x >> s[2].y) {g[1][2] = g[2][1] = walk(1, 2);int j = 0, x, y;c = 3;while (cin >> x >> y) {if (x == -1 && y == -1)j = 0;else {s[c].x = x; s[c].y = y;for (int i = 1; i < c - j; ++i)g[i][c] = g[c][i] = walk(i, c);for (int i = c - j; i < c; ++i)g[i][c] = g[c][i] = subway(i, c);j = 1; ++c;}}--c;floyd();printf("%.0f\n", g[1][2]);}return 0;}

0 0