zoukankan      html  css  js  c++  java
  • 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;
    }
    
    /*
    */
  • 相关阅读:
    redis 集群目标、集群查看、配置方法及过程、哨兵配置启动
    redis 事务、Jedis事务处理流程
    redis订阅与发布(把redis作为消息中间件)
    redis 管道技术 pipeline 简介
    redis 适用场景、缓存选择、java实现
    redis 数据淘汰策略与配置
    redis 持久化策略、aof配置、测试、手动持久化、aof文件体积优化
    redis 命令行查看修改配置文件项、配置文件说明
    redis HyperLogLog 基数估算
    redis 命令select、dbsize、清空数据库、info、client
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10735925.html
Copyright © 2011-2022 走看看