感觉和昨天写了的题一模一样。。。 这种题也能用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 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); 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 < ) 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][];
int L[N], R[N];
int num[N];
int segn; int calc(int n, int r) {
return (n + r) / ;
} int main() {
memset(sum, -, sizeof(sum));
scanf("%d%d%d", &n, &b, &q);
sum[b] = n;
sum[] = ;
for(int i = ; i <= q; i++) {
int x, y;
scanf("%d%d", &x, &y);
if(~sum[x] && sum[x] != y) return puts("unfair"), ;
sum[x] = y;
}
int pre = ;
for(int i = ; i <= b; i++) {
if(~sum[i]) {
segn++;
L[segn] = pre + ;
R[segn] = i;
num[segn] = sum[i] - sum[pre];
if(num[segn] < ) return puts("unfair"), ;
pre = i;
}
}
for(int i = ; i <= segn; i++) {
for(int r = ; r < ; r++) {
cost[i][r] = (R[i] + r) / - (L[i] - + r) / ;
}
}
int maxflow = inf;
for(int mask = ; mask < ( << ); mask++) {
int ret = ;
for(int i = ; i < ; i++)
if(mask >> i & ) ret += n / ;
for(int j = ; j <= segn; j++) {
int tmp = ;
for(int i = ; i < ; i++)
if(!(mask >> i & )) tmp += cost[j][i];
ret += min(tmp, num[j]);
}
chkmin(maxflow, ret);
}
puts(maxflow == n ? "fair" : "unfair");
return ;
} /*
*/

Codeforces 628F 最大流转最小割的更多相关文章

  1. Codeforces 1009G Allowed Letters 最大流转最小割 sosdp

    Allowed Letters 最直观的想法是贪心取, 然后网络流取check可不可行, 然后T了. 想到最大流可以等于最小割, 那么我们状压枚举字符代表的6个点连向汇点是否断掉, 然后再枚举64个本 ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E - Goods transportation 最大流转最小割转dp

    E - Goods transportation 思路:这个最大流-> 最小割->dp好巧妙哦. #include<bits/stdc++.h> #define LL long ...

  3. 【bzoj1001】【最短路】【对偶图】【最大流转最小割】狼抓兔子题解

    [BZOJ1001]狼抓兔子 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 18872  Solved ...

  4. Codeforces 724E Goods transportation(最小割转DP)

    [题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...

  5. Codeforces 786E. ALT 最小割+倍增

    E. ALT http://codeforces.com/problemset/problem/786/E 题意: 给出一棵 n 个节点的树与 m 个工人.每个工人有一条上下班路线(简单路径),一个工 ...

  6. Codeforces 1368H - Breadboard Capacity(最小割+线段树维护矩阵乘法)

    Easy version:Codeforces 题面传送门 & 洛谷题面传送门 Hard version:Codeforces 题面传送门 & 洛谷题面传送门 首先看到这种从某一种颜色 ...

  7. Yet Another Maxflow Problem CodeForces - 903G (最小割,线段树)

    大意: 两个n元素集合$A$, $B$, $A_i$与$A_{i+1}$连一条有向边, $B_i$与$B_{i+1}$连一条有向边, 给定$m$条从$A_i$连向$B_j$的有向边, 每次询问修改$A ...

  8. CodeForces E. Goods transportation【最大流+dp最小割】

    妙啊 首先暴力建图跑最大流非常简单,s向每个i连流量为p[i]的边,每个i向t连流量为s[i]的边,每个i向j连流量为c的边(i<j),但是会又T又M 考虑最大流=最小割 然后dp求最小割,设f ...

  9. Codeforces Gym101518H:No Smoking, Please(最小割)

    题目链接 题意 给出一个n*m的酒店,每个点是一个房间,要将这个酒店的房间划分成为两块(一块无烟区,一块吸烟区),相邻的两个房间之间有一条带权边,权值代表空气锁的面积,如果把这条边给去掉,那么需要花费 ...

随机推荐

  1. Ueditor注意的地方

    复制粘贴内容到编辑器上时,一些标签的属性会被过滤,在config.js里添加白名单配置项,例如: whitList: { a: ['target', 'href', 'title', 'class', ...

  2. 【BZOJ5498】[十二省联考2019]皮配(动态规划)

    [BZOJ5498][十二省联考2019]皮配(动态规划) 题面 BZOJ 洛谷 题解 先考虑暴力\(dp\),设\(f[i][j][k]\)表示前\(i\)所学校,有\(j\)人在某个阵营,有\(k ...

  3. 深入理解JVM(4)——对象的创建和访问

    1.对象的创建 在语言层面上,创建对象(例如克隆,反序列化)通常仅仅是一个new关键字而已. 在虚拟机中,对象(文中讨论的对象限于普通 Java 对象,不包括数组和 Class 对象等)的创建过程如下 ...

  4. nowcoder16450 托米的简单表示法

    题目链接 思路 仔细理解一下题意可以发现. 对于每个完整的括号序列都是独立的,然后就想到分治.高度是序列中所有括号序列的最大值,宽度是所有括号序列宽度和\(+1\). 然后仔细想了一下,这种分治应该是 ...

  5. 【译】1. Java反射——引言

    原文地址:http://tutorials.jenkov.com/java-reflection/index.html *By Jakob Jenkov Java的反射机制使得它可以在运行时检查类.接 ...

  6. 继续沿用旧的网络访问模式Apache HTTP 客户端,防止Android9闪退

    注意位置,在application 节点里面.

  7. (二叉树 递归) leetcode 144. Binary Tree Preorder Traversal

    Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3 ...

  8. 使用Eclipse创建动态的web工程

    使用Eclipse创建动态的web工程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.修改工作区的编码 1>.点击Window选择Preferences 2>.将默 ...

  9. JAVA字符串

    字符串   1. 字符串 1.1 字符串概述和特点 java.lang.String类代表字符串. API当中说:Java 程序中的所有字符串字面值(如 "abc" )都作为此类的 ...

  10. 083_Remove Duplicates from Sorted List

    class ListNode: def __init__(self,x): self.val=x self.next=None ####注意这道题并不是把重复元素全部去掉而是保留一个#### #### ...