Dining POJ - 3281
题意:
f个食物,d杯饮料,每个牛都有想吃的食物和想喝的饮料,但食物和饮料每个只有一份 求最多能满足多少头牛。。。。
解析:
一道简单的无源汇拆点最大流 无源汇的一个最大流,先建立超级源s和超级汇t, 把s和食物连接 权值为食物的数量1 ,饮料和t连接 权值为饮料的数量1, 因为牛只要一个就好,所以牛的结点容量为1 把牛拆成u和u’ 中间权值为1, 牛和喜欢的食物、饮料分别建边 权值为INF和1都行
这道题和hdu4292 很相似 传送门:https://www.cnblogs.com/WTSRUVF/p/9202751.html
代码如下:
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #define mem(a,b) memset(a, b, sizeof(a))
- using namespace std;
- const int maxn = , INF = 0x7fffffff;
- int head[maxn], d[maxn], cur[maxn];
- int n, m, s, t, F, D;
- int cnt;
- typedef long long LL;
- struct node{
- int u, v, c, next;
- }Node[maxn*];
- void add_(int u, int v, int c)
- {
- Node[cnt].u = u;
- Node[cnt].v = v;
- Node[cnt].c = c;
- Node[cnt].next = head[u];
- head[u] = cnt++;
- }
- void add(int u, int v, int c)
- {
- add_(u, v, c);
- add_(v, u, );
- }
- bool bfs()
- {
- queue<int> Q;
- mem(d, );
- Q.push(s);
- d[s] = ;
- while(!Q.empty())
- {
- int u = Q.front(); Q.pop();
- for(int i=head[u]; i!=-; i=Node[i].next)
- {
- node e = Node[i];
- if(!d[e.v] && e.c > )
- {
- d[e.v] = d[e.u] + ;
- Q.push(e.v);
- // cout<< e.v << " " << t <<endl;
- if(e.v == t) return ;
- }
- }
- }
- return d[t] != ;
- }
- int dfs(int u, int cap)
- {
- if(u == t || cap == )
- return cap;
- int ret = ;
- for(int &i=cur[u]; i!=-; i=Node[i].next)
- {
- node e = Node[i];
- if(d[e.v] == d[e.u] + && e.c > )
- {
- int V = dfs(e.v, min(cap, e.c));
- Node[i].c -= V;
- Node[i^].c += V;
- cap -= V;
- ret += V;
- if(cap == ) break;
- }
- }
- return ret;
- }
- int dinic()
- {
- int ans = ;
- while(bfs())
- {
- // cout<< 2111 <<endl;
- memcpy(cur, head, sizeof(head));
- ans += dfs(s, INF);
- // cout<< ans <<endl;
- }
- return ans;
- }
- int main()
- {
- cnt = ;
- mem(head, -);
- cin>> n >> F >> D;
- s = , t = F + D + n + n + ;
- for(int i=; i<=F; i++)
- add(s, i, );
- for(int i=; i<=D; i++)
- add(F+i, t, );
- for(int i=; i<=n; i++)
- add(F+D+i, F+D+n+i, );
- for(int i=; i<=n; i++)
- {
- int r, l;
- cin>> r >> l;
- for(int j=; j<r; j++)
- {
- int u;
- cin>> u;
- add(u, F+D+i, INF);
- }
- for(int j=; j<=l; j++)
- {
- int v;
- cin>> v;
- add(F+D+n+i, F+v, INF);
- }
- }
- cout<< dinic() <<endl;
- return ;
- }
Dining POJ - 3281的更多相关文章
- B - Dining - poj 3281(最大流)
题目大意:有一群牛,还有一些牛喜欢的食物和喜欢的饮料,不过这些牛都很特别,他们不会与别的牛吃同一种食物或者饮料,现在约翰拿了一些食物和饮料,同时他也知道这些牛喜欢的食物和饮料的种类,求出来最多能让多少 ...
- AC日记——Dining poj 3281
[POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...
- kuangbin专题专题十一 网络流 Dining POJ - 3281
题目链接:https://vjudge.net/problem/POJ-3281 题目:有不同种类的食物和饮料,每种只有1个库存,有N头牛,每头牛喜欢某些食物和某些饮料,但是一头牛 只能吃一种食物和喝 ...
- B - Dining POJ - 3281 网络流
Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...
- poj 3281 Dining 网络流-最大流-建图的题
题意很简单:JOHN是一个农场主养了一些奶牛,神奇的是这些个奶牛有不同的品味,只喜欢吃某些食物,喝某些饮料,傻傻的John做了很多食物和饮料,但她不知道可以最多喂饱多少牛,(喂饱当然是有吃有喝才会饱) ...
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
- POJ 3281 Dining(最大流)
POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的 ...
- POJ 3281 网络流dinic算法
B - Dining Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- poj 3281 最大流+建图
很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...
随机推荐
- wifidog源码分析 - 客户端检测线程
引言 当wifidog启动时,会启动一个线程(thread_client_timeout_check)维护客户端列表,具体就是wifidog必须定时检测客户端列表中的每个客户端是否在线,而wifido ...
- Oracle 把查询的多个字段赋值给多个变量
select f1,f2,f3 into v1,v2,v3 from tab1
- Spring-bean的循环依赖以及解决方式
链接:https://blog.csdn.net/u010853261/article/details/77940767 https://www.jianshu.com/p/6c359768b1dc
- CF1105E Helping Hiasat 最大团
传送门 发现自己不会求最大团了可海星 如果将每一个朋友看做点,将两个\(1\)之间存在\(2\)操作的所有朋友之间互相连边,那么我们最后要求的就是这个图的最大独立集. 某个图的最大独立集就是反图的最大 ...
- React-页面路由参数传递的两种方法
list页->detail页 方法一:路由参数 路由导航: 用“/” <Link to={'/detail/'+item.get('id')} key={index}> 路由map: ...
- .NET Core 3.0 跟踪
Preview1: https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-ope ...
- (原创)odoo关系字段在视图中的行为控制 总结
字段类型 选项或属性 格式示例 描述 many2one , many2many_tags(widget) no_create options='{"no_create":True} ...
- 汇编 指令lodsb,lodsw,lodsd
知识点: 汇编指令 lodsb,lodsw,lodsd 一.汇编指令LODSB //scasb scasw scasd //stosb stosw stosd 1. __asm lodsb //作用 ...
- [React]全自动数据表格组件——BodeGrid
表格是在后台管理系统中用的最频繁的组件之一,相关的功能有数据的新增和编辑.查询.排序.分页.自定义显示以及一些操作按钮.我们逐一深入进行探讨以及介绍我的设计思路: 新增和编辑 想想我们最开始写新增 ...
- SqlServer 案例:已有汽车每日行驶里程数据,计算其每日增量
需求说明 某公司某项业务,需要获得用户每日行车里程数.已知能获得该车每日提交的总里程数,如何通过 T-SQL 来获得其每日增量里程? 解决方案 首选需要对数据进行编号,利用开窗函数 OVER() 实现 ...