mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 22:28:48 +00:00
P1522 [USACO2.4]牛的旅行 Cow Tours
R53816523
This commit is contained in:
parent
2f0f88a28f
commit
28889a5392
52
Luogu/problem/P1522/P1522.cpp
Normal file
52
Luogu/problem/P1522/P1522.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, t;
|
||||
double g[155][155], d[155], l1, l2 = 1e9, ans;
|
||||
pair<int, int> m[155];
|
||||
|
||||
double dis(pair<int, int> a, pair<int, int> 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user