[POJ-3281]

思路:

  把牛拆点;

  s向食物连边,流量1;

  饮料向t连边,流量1;

  食物向牛1连边,流量1;

  牛2向饮料连边,流量1;

  最大流;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 2005
#define INF 0x7fffffff int n,f,d,s,t,head[maxn],E[maxn<<],V[maxn<<],F[maxn<<];
int cnt=,deep[maxn],que[maxn<<]; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(int u,int v,int f)
{
E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,F[cnt]=,head[v]=cnt;
} inline bool bfs()
{
for(int i=s;i<=t;i++) deep[i]=-;
int h=,tail=;deep[s]=,que[h]=s;
while(h<tail)
{
int now=que[h++];
for(int i=head[now];i;i=E[i])
{
if(deep[V[i]]<&&F[i]>)
{
deep[V[i]]=deep[now]+;
if(V[i]==t) return true;
que[tail++]=V[i];
}
}
}
return false;
} int flowing(int now,int flow)
{
if(flow<=||now==t) return flow;
int oldflow=;
for(int i=head[now];i;i=E[i])
{
if(F[i]>&&deep[V[i]]==deep[now]+)
{
int pos=flowing(V[i],min(flow,F[i]));
flow-=pos,oldflow+=pos,F[i]-=pos,F[i^]+=pos;
if(flow==) return oldflow;
}
}
if(oldflow==) deep[now]=-;
return oldflow;
} int main()
{
in(n),in(f),in(d);
int u,v,nf,nd;t=f+n+n+d+;
for(int i=;i<=f;i++) edge_add(s,i,);
for(int i=;i<=d;i++) edge_add(f+n+n+i,t,);
for(int i=;i<=n;i++)
{
edge_add(f+i,f+n+i,),in(nf),in(nd);
for(int j=;j<=nf;j++) in(u),edge_add(u,f+i,);
for(int j=;j<=nd;j++) in(u),edge_add(f+n+i,f+n+n+u,);
}
int ans=;
while(bfs()) ans+=flowing(s,INF);
cout<<ans;
return ;
}

AC日记——Dining poj 3281的更多相关文章

  1. AC日记——Tree poj 3237

    Tree Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 9233   Accepted: 2431 Description ...

  2. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  3. AC日记——Crane poj 2991

    POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...

  4. AC日记——pigs poj 1149

    POJ - 1149 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include <iostream> # ...

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

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

  6. Dining POJ - 3281

    题意: f个食物,d杯饮料,每个牛都有想吃的食物和想喝的饮料,但食物和饮料每个只有一份 求最多能满足多少头牛.... 解析: 一道简单的无源汇拆点最大流   无源汇的一个最大流,先建立超级源s和超级汇 ...

  7. AC日记——Two poj 1849

    Two 思路: 树形DP求直径: 答案是边权总和*2-直径: dp[i][1]::以i为根的子树中最长的路径: dp[i][0]::以i为根的子树中次长的路径: 来,上代码: #include < ...

  8. AC日记——Oulipo poj 3461

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37958   Accepted: 15282 Description The ...

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

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

随机推荐

  1. 内部类inner class

    1.什么是内部类,为什么要用内部类? 可以将一个类定义在另一个类的定义内部,这就是内部类. 当描述事物时,事物的内部还有事物,该事物用内部类来描述,因为内部事物在使用外部事物的内容. 如: class ...

  2. 无限小数转分数POJ1930分析

    将无限小数化为分数,有一套简单的公式.使其轻松表示出来. 循环节 例如:0.121212…… 循循环节为12.   公式 这个公式必须将循环节的开头放在十分位.若不是可将原数乘10^x(x为正整数) ...

  3. 《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目7

    2014-04-24 22:06 题目:搜索引擎问题,如果有一列100台服务器的集群,用来响应查询请求,你要如何设计query分发和cache策略? 解法:query分发可以用计算数字签名并对机器数取 ...

  4. 《Cracking the Coding Interview》——第6章:智力题——题目3

    2014-03-20 00:48 题目:有3升的瓶子和5升的瓶子,只允许倒满.倒到满为止.或是泼光三种操作,怎么搞出4升水呢? 解法:如果A和B是互质的两个正整数,且A<B,令X=B-A,则(X ...

  5. DOS程序员手册(十一)

    560页 版本5中新增加的子功能05h支持程序截获MS-DOS EXEC调用,并实 现自我装载.该子功能能实现内存的修补,如设置装载程序能接收的版本号 (通过SETVER设置的版本号)以及实现对装载程 ...

  6. USACO Section1.2 Palindromic Squares 解题报告

    palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  7. leetcode 【 Remove Duplicates from Sorted List 】 python 实现

    题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...

  8. java IO小结

    package 字符与字节转换; import java.io.*; public class char_byte { public static void main(String[] args) { ...

  9. Opencv3.3.1安装包

    这个资源是Opencv3.3.1安装包,包括Windows软件包,Android软件包,IOS软件包,还有opencv的源代码:需要的下载吧. 点击下载

  10. 操作App.config的类(转载)

    http://www.cnblogs.com/yaojiji/archive/2007/12/17/1003191.html 操作App.config的类 public class DoConfig  ...