题意

$m$个不同单位代表参加会议,第$i$个单位有$r_i$个人

$n$张餐桌,第$i$张可容纳$c_i$个代表就餐

同一个单位的代表需要在不同的餐桌就餐

问是否可行,要求输出方案

Sol

比较zz的最大流

从$S$向$1-m$连流量为$r_i$的边

从$m + 1$向$m + n$连流量为$c_i$的边

从$1-m$向$m + 1$到$m + n$中的每个点连流量为$1$的边

跑最大流即可

#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int MAXN = 1e5 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int M, N, S, T;
int r[MAXN], c[MAXN];
struct Edge {
int u, v, f, nxt;
}E[MAXN];
int head[MAXN], cur[MAXN], num;
inline void add_edge(int x, int y, int f) {
E[num] = (Edge){x, y, f, head[x]};
head[x] = num++;
}
inline void AddEdge(int x, int y, int z) {
add_edge(x, y, z);
add_edge(y, x, );
}
int sum = , deep[MAXN];
bool BFS() {
queue<int> q; q.push(S);
memset(deep, , sizeof(deep)); deep[S] = ;
while(!q.empty()) {
int p = q.front(); q.pop();
for(int i = head[p]; i != -; i = E[i].nxt) {
int to = E[i].v;
if(!deep[to] && E[i].f) {
deep[to] = deep[p] + ;
q.push(to);
}
}
}
return deep[T] > ;
}
int DFS(int x, int flow) {
if(x == T) return flow;
int ansflow = ;
for(int &i = cur[x]; i != -; i = E[i].nxt) {
int to = E[i].v;
if(deep[to] == deep[x] + && E[i].f) {
int nowflow = DFS(to, min(flow, E[i].f));
E[i].f -= nowflow; E[i ^ ].f += nowflow;
ansflow += nowflow; flow -= nowflow;
if(flow <= ) break;
}
}
return ansflow;
}
int Dinic() {
int ans = ;
while(BFS()) {
memcpy(cur, head, sizeof(head));
ans += DFS(S, INF);
}
return ans;
}
int main() {
memset(head, -, sizeof(head));
M = read(); N = read(); S = ; T = M + N + ;
for(int i = ; i <= M; i++) r[i] = read(), AddEdge(S, i, r[i]), sum += r[i];
for(int i = ; i <= N; i++) c[i] = read(), AddEdge(i + M, T, c[i]);
for(int i = ; i <= M; i++)
for(int j = ; j <= N; j++)
AddEdge(i, j + M, );
if(Dinic() >= sum) printf("1\n");
else {printf(""); return ;}
for(int x = ; x <= M; x++) {
for(int i = head[x]; i != -; i = E[i].nxt)
if(E[i].f == )
printf("%d ", E[i].v - M);
puts("");
}
return ;
}

洛谷P3254 圆桌问题(最大流)的更多相关文章

  1. 洛谷P3254 圆桌问题(最大流)

    传送门 一道良心啊……没那么多麻烦了…… 从$S$向所有单位连边,容量为单位人数,从所有桌子向$T$连边,容量为桌子能坐的人数,从每一个单位向所有桌子连边,容量为$1$,然后跑一个最大流,看一看$S$ ...

  2. 洛谷 P3254 圆桌问题【最大流】

    s向所有单位连流量为人数的边,所有饭桌向t连流量为饭桌容量的边,每个单位向每个饭桌连容量为1的边表示这个饭桌只能坐这个单位的一个人.跑dinic如果小于总人数则无解,否则对于每个单位for与它相连.满 ...

  3. 洛谷 [P3254] 圆桌问题

    简单最大流建图 #include <iostream> #include <cstdio> #include <cstring> #include <cmat ...

  4. 洛谷.3254.圆桌问题(最大流ISAP)

    题目链接 日常水题 还是忍不住吐槽这题奇怪的评价 #include <cstdio> #include <cctype> #include <algorithm> ...

  5. [洛谷P3254]圆桌问题

    题目大意:有$m$个单位,每个单位有$r_i$个代表,有$n$张餐桌,每张餐桌可容纳$c_i$个代表.要求同一个单位的代表不在同一个餐桌就餐.若可以,输出$1$以及其中一种方案,否则输出$0$ 题解: ...

  6. 洛谷P3254 圆桌问题 网络流_二分图

    Code: #include<cstdio> #include<algorithm> #include<vector> #include<queue> ...

  7. Luogu P3254 圆桌问题(最大流)

    P3254 圆桌问题 题面 题目描述 假设有来自 \(m\) 个不同单位的代表参加一次国际会议.每个单位的代表数分别为 \(r_i (i =1,2,--,m)\) . 会议餐厅共有 \(n\) 张餐桌 ...

  8. 洛谷.4015.运输问题(SPFA费用流)

    题目链接 嗯..水题 洛谷这网络流二十四题的难度评价真神奇.. #include <queue> #include <cstdio> #include <cctype&g ...

  9. [洛谷P3254] [网络流24题] 圆桌游戏

    Description 假设有来自m 个不同单位的代表参加一次国际会议.每个单位的代表数分别为ri (i =1,2,--,m). 会议餐厅共有n 张餐桌,每张餐桌可容纳ci (i =1,2,--,n) ...

随机推荐

  1. linux网络配置及IP绑定

    在学习时,参考了这篇文章:http://blog.csdn.net/collection4u/article/details/14127671:在这篇文章中作者讲述了VMware中虚机的三种网络模式: ...

  2. Linux内核中工作队列的使用work_struct,delayed_work【转】

    本文转载自:http://blog.csdn.net/zahuopuboss/article/details/43268983 初始化工作队列 调度工作队列 取消工作队列 #include <l ...

  3. kentico检查当前授权用户,是否为admin角色

    https://docs.kentico.com/k11/custom-development/user-internals-and-api/checking-permissions-using-th ...

  4. fuse的编译安装(Centos7-minimal)

    打算寒假在家跟着THU的一个分布式系统的课程:http://thu-cmu.cs.tsinghua.edu.cn/curriculum/dscourse/schedule.htm 第0个lab就是要在 ...

  5. git push不成功 insufficient permission for adding an object to repository database

    这常见于多用户. 1. 确保所有用户在同一个组: 2. 确保所有文件被组可读写. 当多个用户各自进行了push操作后,object目录下的文件可能各自属于各个用户.

  6. 推箱子 Sokoban(华中农业比赛)

    点这里 打开题目链接   点击打开链接 题目就是我们玩过的推箱子: 一顿暴力广搜:加状态标记.状态压缩需要用到一个类似于康拓的思想来压缩:所以容易TLE,搜索就是用一个int型的数字来表示一个状态, ...

  7. 内部类 final变量的生命周期

    (1).内部类是外部类的一个成员,就像外部类的成员方法一样,所以内部类有权限访问外部类的所有成员,包括private的. (2).内部类不能访问外部类方法中的局部变量,除非变量是final的(一般发生 ...

  8. BZOJ_5311_贞鱼_决策单调性+带权二分

    BZOJ_5311_贞鱼_决策单调性+带权二分 Description 众所周知,贞鱼是一种高智商水生动物.不过他们到了陆地上智商会减半. 这不?他们遇到了大麻烦! n只贞鱼到陆地上乘车,现在有k辆汽 ...

  9. RDA TDT & TOT

    首先看下面的TS PSI分析图: 注意:TOT UTC与TDT是一致的 TDT下的时间为: UTC+手动TIMEZONE TOT下的时间为: UTC+解析的time_offset time_offes ...

  10. ASP.NET Core:目录

    ylbtech-ASP.NET Core:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http:// ...