AC日记——Dining poj 3281
[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的更多相关文章
- AC日记——Tree poj 3237
Tree Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 9233 Accepted: 2431 Description ...
- AC日记——Dividing poj 1014
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69575 Accepted: 18138 Descri ...
- AC日记——Crane poj 2991
POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...
- AC日记——pigs poj 1149
POJ - 1149 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include <iostream> # ...
- B - Dining - poj 3281(最大流)
题目大意:有一群牛,还有一些牛喜欢的食物和喜欢的饮料,不过这些牛都很特别,他们不会与别的牛吃同一种食物或者饮料,现在约翰拿了一些食物和饮料,同时他也知道这些牛喜欢的食物和饮料的种类,求出来最多能让多少 ...
- Dining POJ - 3281
题意: f个食物,d杯饮料,每个牛都有想吃的食物和想喝的饮料,但食物和饮料每个只有一份 求最多能满足多少头牛.... 解析: 一道简单的无源汇拆点最大流 无源汇的一个最大流,先建立超级源s和超级汇 ...
- AC日记——Two poj 1849
Two 思路: 树形DP求直径: 答案是边权总和*2-直径: dp[i][1]::以i为根的子树中最长的路径: dp[i][0]::以i为根的子树中次长的路径: 来,上代码: #include < ...
- AC日记——Oulipo poj 3461
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37958 Accepted: 15282 Description The ...
- kuangbin专题专题十一 网络流 Dining POJ - 3281
题目链接:https://vjudge.net/problem/POJ-3281 题目:有不同种类的食物和饮料,每种只有1个库存,有N头牛,每头牛喜欢某些食物和某些饮料,但是一头牛 只能吃一种食物和喝 ...
随机推荐
- python 三目运算
python中的三目运算: result = a if condition else b #当满足condition返回a否则返回b 三目运算可以使你的代码看起来简洁,且运算高效
- CSS系列(5)-如何使用Firebug查看网页的html和css
Firebug是火狐浏览器Firefox的一个插件,专门为开发人员开发的.使用Firebug需要先在Firefox中安装这个插件,网上有很多教程,可以对照着安装一下. 不同的火狐浏览器版本中的Fire ...
- Oracle 学习---- 练习语法 循环( loop end loop; for ;while; if elsif end if )
/*--set serveroutput on;declare mynum number(3) :=0; tip varchar2(10):='结果是 ';begin mynum:=10+100; d ...
- NOIP2018 集训(二)
A题 神炎皇 问题描述 神炎皇乌利亚很喜欢数对,他想找到神奇的数对. 对于一个整数对 \((a,b)\) ,若满足 \(a+b\leq n\) 且 \(a+b\) 是 \(ab\) 的因子,则称 为神 ...
- NTP学习
NTP(The Network Time Protocol),本以为是一个非常简单的协议,但是看了百度百科和ntp.org的介绍后,我发现我错了. 这个看似简单的协议存在一个很关键也是非常重要的问题- ...
- leetcode 179. 最大数 解题报告
给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 示例 1: 输入: [10,2] 输出: 210 示例 2: 输入: [3,30,34,5,9] 输出: 9534330 说明: 输出结果 ...
- ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
这是在python中使用caffe产生的错误. 程序很普通: #-*-coding=utf-8-*- import numpy as npimport matplotlib.pyplot as plt ...
- CPU指令集不同导致的core分析
最近程序需要支持CGSL系统运行,测试中发现相同操作系统的两台机器,编译机运行正常,测试机coredump.core信息汇总如下,可以看出是由于测试机不支持编译后的指令导致的问题: Program t ...
- Axios & cookie
Axios & cookie `withCredentials: true https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRe ...
- [洛谷P4346][CERC2015]ASCII Addition
题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...