题意

$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. [RK3288][Android6.0] 调试笔记 --- 系统识别不同硬件版本方法【转】

    本文转载自:http://m.blog.csdn.net/kris_fei/article/details/70226451 Platform: RockchipOS: Android 6.0Kern ...

  2. caioj1465&&poj1024: 【AC自动机】地图匹配

    刷的第二题AC自动机,这题简直了.. 用询问的串建AC自动机,然后...爆搜! ACBB                  ACBBACCA                  A  AABBC     ...

  3. 合并table中某一列相邻的相同的行

    合并table中某一列相邻的相同的行​1. [代码]合并table中某一列相邻的相同的行  <!DOCTYPE html><html>    <head>      ...

  4. 【Java】DateUtil(1)

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  5. Python中的sort() key含义

    sorted(iterable[, cmp[, key[, reverse]]]) iterable.sort(cmp[, key[, reverse]]) 参数解释: (1)iterable指定要排 ...

  6. [CQOI 2015] 任务查询系统

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3932 [算法] 首先 , 我们可以将(Si , Ei , Pi)转化为在Si处加入P ...

  7. Vue中devtools安装使用

    vue.js的devtools安装 安装 1.github下载地址:https://github.com/vuejs/vue-devtools 2.下载好后进入vue-devtools-master工 ...

  8. CodeForces 712A Memory and Crow (水题)

    题意:有一个序列,然后对每一个进行ai = bi - bi + 1 + bi + 2 - bi + 3.... 的操作,最后得到了a 序列,给定 a 序列,求原序列. 析:很容易看出来,bi = ai ...

  9. C++经典面试题库 附带参考答案

    1.    面向对象的程序设计思想是什么? 答:把数据结构和对数据结构进行操作的方法封装形成一个个的对象. 2.    什么是类? 答:把一些具有共性的对象归类后形成一个集合,也就是所谓的类. 3.  ...

  10. poj1163 【记忆化搜索·水】

    题意: 一个这样的三角形,他可以往下的左或者往下的右走.求一个在最后一行的最大. 思路: 额...就是搜一下..记录一下...肯定有重合的情况. code- //#include <bits/s ...