From 28889a539213978da9b1d2cfc8dbf5eb1366167b Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 21 Jul 2021 17:54:35 +0800 Subject: [PATCH] =?UTF-8?q?P1522=20[USACO2.4]=E7=89=9B=E7=9A=84=E6=97=85?= =?UTF-8?q?=E8=A1=8C=20Cow=20Tours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R53816523 --- Luogu/problem/P1522/P1522.cpp | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Luogu/problem/P1522/P1522.cpp diff --git a/Luogu/problem/P1522/P1522.cpp b/Luogu/problem/P1522/P1522.cpp new file mode 100644 index 00000000..4d416554 --- /dev/null +++ b/Luogu/problem/P1522/P1522.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int n, t; +double g[155][155], d[155], l1, l2 = 1e9, ans; +pair m[155]; + +double dis(pair a, pair b) { + return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2)); +} + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> m[i].first >> m[i].second; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + scanf("%1d", &t); + if (t) { + g[i][j] = dis(m[i], m[j]); + } else { + g[i][j] = i == j ? 0 : 1e9; + } + } + } + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + g[i][j] = min(g[i][j], g[i][k] + g[k][j]); + } + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (g[i][j] != 1e9) { + d[i] = max(g[i][j], d[i]); + } + l1 = max(l1, d[i]); + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (g[i][j] == 1e9) { + l2 = min(l2, d[i] + dis(m[i], m[j]) + d[j]); + } + } + } + cout << fixed << setprecision(6) << max(l1, l2) << endl; + return 0; +}