1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<utility> #include<algorithm> #include<map> #include<queue> #include<vector> #include<list> #include<functional> #include<string> #define INF 0x7fffffff using namespace std; int n; int posx[200], posy[200]; double arr[200][200]; double sglgdis[200]; inline double distance(int x1, int y1, int x2, int y2) { //最后开根号,函数中未开根号 return sqrt((double)(x1 - x2)*(x1 - x2) + (double)(y1 - y2)*(y1 - y2)); } void floyd() { for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (arr[i][j] > arr[i][k] + arr[k][j]) { arr[i][j] = arr[i][k] + arr[k][j]; } } } } } int main() { for (int i = 0; i <= 199; i++) { for (int j = 0; j <= 199; j++) { arr[i][j] = INF; } } scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &posx[i], &posy[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int t; scanf("%1d", &t); arr[i][j] = (t||i==j) ? distance(posx[i], posy[i], posx[j], posy[j]) : INF; if (i == j)arr[i][j] = 0; } } floyd(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (arr[i][j] != INF&&arr[i][j] > sglgdis[i]) { sglgdis[i] = arr[i][j]; } } } double mmm = INF; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (arr[i][j] < INF)continue; double t = sglgdis[i] + sglgdis[j] + distance(posx[i], posy[i], posx[j], posy[j]); if (t < mmm)mmm = t; } } for (int i = 1; i <= n; i++) { if (sglgdis[i] > mmm)mmm = sglgdis[i]; } printf("%.6lf\n", mmm); } |
洛谷 牛的旅行 Cow Tours
发表评论