mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-13 09:58:47 +00:00
parent
1dfb3067fc
commit
0dd2f8f42b
112
BZOJ/3232/3232.cpp
Normal file
112
BZOJ/3232/3232.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <queue>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 55;
|
||||
const double eps = 1e-6;
|
||||
|
||||
int n, m, s[N][N];
|
||||
std::vector<std::tuple<int, int, int>> g[N * N];
|
||||
int cnt[N * N];
|
||||
double dist[N * N];
|
||||
bool vis[N * N];
|
||||
|
||||
int id(int x, int y) {
|
||||
return (x - 1) * (m + 1) + y;
|
||||
}
|
||||
|
||||
bool check(double x) {
|
||||
std::fill(std::begin(cnt), std::end(cnt), 0);
|
||||
std::fill(std::begin(dist), std::end(dist), -1e9);
|
||||
std::fill(std::begin(vis), std::end(vis), false);
|
||||
|
||||
std::queue<int> q;
|
||||
|
||||
q.emplace(1);
|
||||
dist[1] = 0;
|
||||
vis[1] = true;
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
q.pop();
|
||||
|
||||
vis[u] = false;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v, a, b;
|
||||
|
||||
std::tie(v, a, b) = e;
|
||||
|
||||
double w = static_cast<double>(b) - x * a;
|
||||
|
||||
if (dist[v] < dist[u] + w) {
|
||||
dist[v] = dist[u] + w;
|
||||
|
||||
if (!vis[v]) {
|
||||
cnt[v] = cnt[u] + 1;
|
||||
|
||||
if (cnt[v] > (n + 1) * (m + 1)) return false;
|
||||
|
||||
vis[v] = true;
|
||||
q.emplace(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1, x; j <= m; j++) {
|
||||
cin >> x;
|
||||
|
||||
s[i][j] = s[i][j - 1] + x;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n + 1; i++) {
|
||||
for (int j = 1, x; j <= m; j++) {
|
||||
cin >> x;
|
||||
|
||||
g[id(i, j)].emplace_back(id(i, j + 1), x, 0);
|
||||
g[id(i, j + 1)].emplace_back(id(i, j), x, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1, x; j <= m + 1; j++) {
|
||||
cin >> x;
|
||||
|
||||
g[id(i, j)].emplace_back(id(i + 1, j), x, -s[i][j - 1]);
|
||||
g[id(i + 1, j)].emplace_back(id(i, j), x, s[i][j - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
double l = 0, r = 1000;
|
||||
|
||||
while (r - l > eps) {
|
||||
double mid = (l + r) / 2;
|
||||
|
||||
if (check(mid)) r = mid;
|
||||
else l = mid;
|
||||
}
|
||||
|
||||
cout << std::fixed << std::setprecision(3) << l << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/3232/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/3232/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/3232/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user