题意:

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的更多相关文章

  1. B - Dining - poj 3281(最大流)

    题目大意:有一群牛,还有一些牛喜欢的食物和喜欢的饮料,不过这些牛都很特别,他们不会与别的牛吃同一种食物或者饮料,现在约翰拿了一些食物和饮料,同时他也知道这些牛喜欢的食物和饮料的种类,求出来最多能让多少 ...

  2. AC日记——Dining poj 3281

    [POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...

  3. kuangbin专题专题十一 网络流 Dining POJ - 3281

    题目链接:https://vjudge.net/problem/POJ-3281 题目:有不同种类的食物和饮料,每种只有1个库存,有N头牛,每头牛喜欢某些食物和某些饮料,但是一头牛 只能吃一种食物和喝 ...

  4. B - Dining POJ - 3281 网络流

    Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...

  5. poj 3281 Dining 网络流-最大流-建图的题

    题意很简单:JOHN是一个农场主养了一些奶牛,神奇的是这些个奶牛有不同的品味,只喜欢吃某些食物,喝某些饮料,傻傻的John做了很多食物和饮料,但她不知道可以最多喂饱多少牛,(喂饱当然是有吃有喝才会饱) ...

  6. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  7. POJ 3281 Dining(最大流)

    POJ 3281 Dining id=3281" target="_blank" style="">题目链接 题意:n个牛.每一个牛有一些喜欢的 ...

  8. POJ 3281 网络流dinic算法

    B - Dining Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  9. poj 3281 最大流+建图

    很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...

随机推荐

  1. CMD命令查看当前电脑安装所有版本.NET Core SDK(转载)

    dotnet --version 查看当前使用版本 dotnet --info 安装的所有版本 包括版本地址 也可用命令帮助 dotnet help 原文链接

  2. 如何学习 Webpack

    webpack-howto Tip: 本文是 webpack-howto 的原文,我觉得这篇文章写得非常好,确实算是目前学习 webpack 入门的必读文章.直接收录之. 本教程的目标 这是一本教你如 ...

  3. BZOJ1816 CQOI2010 扑克牌 贪心

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1816 题意:有$N$堆牌,第$i$堆牌有$c_i$张牌,还有$M$张$joker$,每 ...

  4. 《Java程序设计》教学进程

    <Java程序设计>教学进程 目录 考核方式 课前准备 教学进程 第00周学习任务和要求 第01周学习任务和要求 第02周学习任务和要求 第03周学习任务和要求 第04周学习任务和要求 第 ...

  5. 洛谷 P4409 [ZJOI2006] 皇帝的烦恼

    题目链接-> OVO 题解: 很久没有写博客了,可能是因为最近太颓废了吧. 刚刚考完期末考试,无比期盼早点外出学习,不要面对成绩,害怕. #include <cstdio> #inc ...

  6. pycharm2019注册码一键实时获取,永久有效!

    pycharm2019专业版激活码 56ZS5PQ1RF-eyJsaWNlbnNlSWQiOiI1NlpTNVBRMVJGIiwibGljZW5zZWVOYW1lIjoi5q2j54mI5o6I5p2 ...

  7. Centos7部署elasticsearch并且安装ik分词以及插件kibana

    第一步 下载对应的安装包 elasticsearch下载地址:https://www.elastic.co/cn/downloads/elasticsearch ik分词下载:https://gith ...

  8. Aop笔记

    参考: https://blog.csdn.net/bombSKLK/article/details/79143145 示例 拦截的 注解的方法 @Around("@annotation(c ...

  9. linux下日志文件error监控报警脚本分享

    即对日志文件中的error进行监控,当日志文件中出现error关键字时,即可报警!(grep -i error 不区分大小写进行搜索"error"关键字,但是会将包含error大小 ...

  10. C. Meme Problem

    链接 [http://codeforces.com/contest/1076/problem/C] 题意 a+b=d and a⋅b=d. 计算出a和b 分析 ab=a(d-a)=d aa-ad+d= ...