Codeforces 628F 最大流转最小割
感觉和昨天写了的题一模一样。。。 这种题也能用hall定理取check, 感觉更最小割差不多。
#include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() #define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = 1e4 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;} template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;} template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;} template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int n, b, q, sum[N]; int cost[N][5]; int L[N], R[N]; int num[N]; int segn; int calc(int n, int r) { return (n + r) / 5; } int main() { memset(sum, -1, sizeof(sum)); scanf("%d%d%d", &n, &b, &q); sum[b] = n; sum[0] = 0; for(int i = 1; i <= q; i++) { int x, y; scanf("%d%d", &x, &y); if(~sum[x] && sum[x] != y) return puts("unfair"), 0; sum[x] = y; } int pre = 0; for(int i = 1; i <= b; i++) { if(~sum[i]) { segn++; L[segn] = pre + 1; R[segn] = i; num[segn] = sum[i] - sum[pre]; if(num[segn] < 0) return puts("unfair"), 0; pre = i; } } for(int i = 1; i <= segn; i++) { for(int r = 0; r < 5; r++) { cost[i][r] = (R[i] + r) / 5 - (L[i] - 1 + r) / 5; } } int maxflow = inf; for(int mask = 0; mask < (1 << 5); mask++) { int ret = 0; for(int i = 0; i < 5; i++) if(mask >> i & 1) ret += n / 5; for(int j = 1; j <= segn; j++) { int tmp = 0; for(int i = 0; i < 5; i++) if(!(mask >> i & 1)) tmp += cost[j][i]; ret += min(tmp, num[j]); } chkmin(maxflow, ret); } puts(maxflow == n ? "fair" : "unfair"); return 0; } /* */