http://acm.hdu.edu.cn/showproblem.php?pid=4560

网络流好像经常搭配上二分和拆点。

n个歌手,m种歌曲流派(n<=m<=75)

我们想要安排尽可能多的演唱会。不过有以下条件——

1,每场演唱会中,每个歌手要唱不同类型的歌曲。

2,这样可能导致有些歌手去唱他不擅长的歌曲。对于任一种歌曲,被不合适唱的次数都不能超过L。

问你最多能安排多少场演唱会

想了一想发现最大流不能直接流,因为很难表示一场比赛需要M个流派的条件

发现这道题总共有三个信息,歌手,流派和比赛场次。

我们考虑二分他的比赛场次,对于场次x

源点流向每一个歌手x,x流向他不擅长的歌曲1,或者流向他擅长的歌曲1,然后不擅长的歌曲流向同一首歌的擅长的歌曲K表示最多有K个歌手可以不擅长,最后所有擅长的歌曲流向源点t,x的大小。

这需要将每一首歌曲拆成擅长的和不擅长的两个点进行建图。

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
inline int read(){int now=;register char c=getchar();for(;!isdigit(c);c=getchar());
for(;isdigit(c);now=now*+c-'',c=getchar());return now;}
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
const double eps = 1e-;
const int maxn = 2e5 + ;
const int maxm = 6e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
struct Dinic{
struct Edge{
int from,to,cap,flow,nxt;
Edge() {}
Edge(int u,int v,int c,int f,int n):from(u),to(v),cap(c),flow(f),nxt(n) {}
}edge[maxm];
int n,s,t,E,head[maxn];
bool vis[maxn];
int d[maxn],cur[maxn];
inline void AddEdge(int f,int t,int c){
edge[++E] = Edge(f,t,c,,head[f]);
head[f] = E;
edge[++E] = Edge(t,f,,,head[t]);
head[t] = E;
}
inline void Init(int n,int s,int t){
this -> n = n; E = -;
this -> s = s; head[s] = -;
this -> t = t; head[t] = -;
for(int i = ; i <= n ; i ++) head[i] = -;
} inline bool BFS(){
memset(vis,,sizeof(vis));
queue<int>Q;
d[s] = ;vis[s] = ;
for(Q.push(s);!Q.empty();){
int x = Q.front(); Q.pop();
for(int nxt,i = head[x];~i;i = nxt){
Edge &e = edge[i]; nxt = e.nxt;
if(vis[e.to] || e.cap <= e.flow) continue;
vis[e.to] = ;
d[e.to] = d[x] + ;
Q.push(e.to);
}
}
return vis[t];
} inline int DFS(const int &x,int a){
if(x == t || a == ) return a;
int flow = ,f,nxt;
for(int &i = cur[x]; ~i; i = nxt){
Edge &e = edge[i]; nxt = e.nxt;
if(d[x] + != d[e.to]) continue;
f = DFS(e.to,min(a,e.cap - e.flow));
if(f <= ) continue;
e.flow += f;
edge[i ^ ].flow -= f;
flow += f; a -= f;
if(!a) break;
}
return flow;
}
inline int maxFlow(){return maxFlow(s,t);}
inline int maxFlow(int s,int t){
int flow = ;
for(;BFS();){
for(int i = ;i <= n ; i ++) cur[i] = head[i];
flow += DFS(s,INF);
}
return flow;
}
}g;
int N,M,L,K;
bool MAP[][];
bool check(int x){
int s = ,t = N + M * + ;
g.Init(t,s,t);
For(i,,N) g.AddEdge(s,i,x);
For(i,,N){
For(j,,M){
if(MAP[i][j]){
g.AddEdge(i,j + N,);
}else{
g.AddEdge(i,j + N + M,);
}
}
}
For(i,,M) g.AddEdge(i + N,t,x);
For(i,,M) g.AddEdge(i + N + M,i + N,K);
return ((LL)g.maxFlow() >= ((LL)x * N));
}
int solve(){
int l = ,r = INF;
int ans = ;
while(l <= r){
int m = (l + r) >> ;
if(check(m)){
ans = m;
l = m + ;
}else{
r = m - ;
}
}
return ans;
}
int main()
{
int T; Sca(T);
int CASE = ;
while(T--){
Sca2(N,M); Sca2(L,K); Mem(MAP,);
For(i,,L){
int x,y; Sca2(x,y);
MAP[x][y] = ;
}
printf("Case %d: ",CASE++);
Pri(solve());
}
#ifdef VSCode
system("pause");
#endif
return ;
}

HDU4560 二分最大流的更多相关文章

  1. hdu4560 不错的建图,二分最大流

    题意: 我是歌手 Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Subm ...

  2. uvalive 3231 Fair Share 公平分配问题 二分+最大流 右边最多流量的结点流量尽量少。

    /** 题目: uvalive 3231 Fair Share 公平分配问题 链接:https://vjudge.net/problem/UVALive-3231 题意:有m个任务,n个处理器,每个任 ...

  3. poj 2391 Ombrophobic Bovines 最短路 二分 最大流 拆点

    题目链接 题意 有\(n\)个牛棚,每个牛棚初始有\(a_i\)头牛,最后能容纳\(b_i\)头牛.有\(m\)条道路,边权为走这段路所需花费的时间.问最少需要多少时间能让所有的牛都有牛棚可待? 思路 ...

  4. HDU3081 Marriage Match II —— 传递闭包 + 二分图最大匹配 or 传递闭包 + 二分 + 最大流

    题目链接:https://vjudge.net/problem/HDU-3081 Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    ...

  5. HDU-3081-Marriage Match II 二分图匹配+并查集 OR 二分+最大流

    二分+最大流: 1 //题目大意:有编号为1~n的女生和1~n的男生配对 2 // 3 //首先输入m组,a,b表示编号为a的女生没有和编号为b的男生吵过架 4 // 5 //然后输入f组,c,d表示 ...

  6. POJ3228二分最大流

    题意:       有n个点,每个点有两个权值,金子数量还有仓库容量,金子可以存在自己的仓库里或者是别的仓库里,仓库和仓库之间有距离,问所有金子都必须存到库里最大距离的最小是多少? 思路:       ...

  7. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  8. loj 1167(二分+最大流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26881 思路:我们可以二分最大危险度,然后建图,由于每个休息点只能 ...

  9. BZOJ-1822 Frozen Nova 冷冻波 计(jie)算(xi)几何+二分+最大流判定+经典建图

    这道逼题!感受到了数学对我的深深恶意(#‵′).... 1822: [JSOI2010]Frozen Nova 冷冻波 Time Limit: 10 Sec Memory Limit: 64 MB S ...

随机推荐

  1. JS实现控制HTML5背景音乐播放暂停

    首先在网页中嵌入背景音乐,html5代码为: <script src="http://wuover.qiniudn.com/jquery.js"></script ...

  2. Nginx http2.0

    109/110 HTTP2.0协议 优势必须使用TLS加密 传输数据量大幅减少 1:以二进制格式传输  2:标头压缩(header做压缩) 多路复用及相关功能 : 消息优先级 (比如样式表先渲染页面那 ...

  3. jsp页面中 <%%> <%! %>, <%=%> <%-- --%>有什么区别

    <%%> 可添加java代码片段   <%! %>       可添加java方法   <%=%>       变量或表达式值输出到页面 <%-- --%&g ...

  4. 51Nod 1381 硬币游戏

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6445369.html 1381 硬币游戏 基准时间限制:1 秒 空间限制:131072 KB 分值 ...

  5. MVC 自定义 错误页面

    很多时候,我们需要自定义错误页面,用来当发生异常后引导用户进入一个比较友好的错误页面. 在这里,我归结一下我常用的2个方案 1   通过Global.asax 文件来处理异常信息(这个不管是 MVC ...

  6. 大学jsp实验5request,response

    1.request对象的使用 (1)编写一个包含有表单的JSP页面form.jsp,其中包含可以输入姓名和出生地的文本框,提交表单后在另一个页面中显示用户提交的姓名和出生地.请写出相应代码: form ...

  7. Power Stations HDU - 3663

    我为什么T了.... Power Stations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  8. python学习日记(基础数据类型及其方法01)

    数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...

  9. LG P2473 [SCOI2008]奖励关

    题目链接:P2473 [SCOI2008]奖励关 题意:有n个宝物 每次等概率抛出其中之一一共抛出k次每个宝物有一个价值 和一个前提集合只有集齐了集合中的所有宝物 才可以领取这个宝物 范围:1 < ...

  10. 多IP加强SSH的安全性

    本文针对一台服务器有多个网卡及IP地址的情况,可以限制某些IP不监听SSH,只允许通过某些IP来登陆 以下配置项在/etc/ssh/sshd_config文件中修改 比如你有4个网卡: eth0 – ...