蒟蒻の疑惑,这道题我用贪心过了,有大佬能帮忙证明一下正确性/hack吗?QWQ

P4251 [SCOI2015] 小凸玩矩阵

```cpp #include <bits/stdc++.h> using namespace std; namespace IO { char buf_[1 << 21], *p1_ = buf_, *p2_ = buf_; #define ch() \ (p1_ == p2_ && \ (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin), p1_ == p2_) \ ? EOF \ : *p1_++) inline int in() { int s = 0, f = 1; char x = ch(); for (; x < '0' || x > '9'; x = ch()) if (x == '-') f = -1; for (; x >= '0' && x <= '9'; x = ch()) s = (s * 10) + (x & 15); return f == 1 ? s : -s; } char _buf[1 << 21]; int _pos = -1; inline void flush() { fwrite(_buf, 1, _pos + 1, stdout); _pos = -1; } inline void pc(char x) { if (_pos == (1 << 21) - 1) flush(); _buf[++_pos] = x; } inline void out(int x) { char k[30]; int pos = 0; if (!x) return pc('0'); if (x < 0) pc('-'), x = -x; while (x) k[++pos] = (x % 10) | 48, x /= 10; for (int i = pos; i; i--) pc(k[i]); } } // namespace IO using namespace IO; const int A = 300; const int INF = 1e9 + 5; int n, m, K; int p[A][A]; int nh[A], nl[A]; inline int check(int x) { for (int i = 1; i <= m; i++) nh[i] = nl[i] = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (p[i][j] <= x) nh[i]++, nl[j]++; nh[0] = nl[0] = INF; int pos = 0; for (int tm = 1; tm <= n - K + 1; tm++) { int h = 0; for (int i = 1; i <= n; i++) if (nh[i] && nh[i] < nh[h]) h = i; if (!h) { pos = 1; break; } int l = 0; for (int i = 1; i <= m; i++) if (p[h][i] <= x && nl[i] && nl[i] < nl[l]) l = i; nh[h] = 0, nl[l] = 0; for (int i = 1; i <= n; i++) if (nh[i] && p[i][l] <= x) nh[i]--; } if (pos) return 0; return 1; } signed main() { // freopen("matrix.in", "r", stdin); // freopen("matrix.out", "w", stdout); n = in(), m = in(), K = in(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) p[i][j] = in(); int L = 1, R = 1e9, ans = 0; while (L <= R) { int mid = (L + R) >> 1; if (check(mid)) R = mid - 1, ans = mid; else L = mid + 1; } out(ans), pc('\n'); flush(); return 0; } /* 2 3 1 1 2 4 2 4 1 */ /* 3 4 2 1 5 6 6 8 3 4 3 6 8 6 3 */ ```
by ghr_226 @ 2020-09-23 13:45:42


做法已被证伪 [传送门](https://www.luogu.com.cn/discuss/show/258922?page=1) ~~建议加强数据~~
by ghr_226 @ 2020-09-24 17:18:10


|