zoj 3229 Shoot the Bullet(有源汇上下界最大流)
Shoot the Bullethttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442
Time Limit: 2 Seconds Memory Limit: 32768 KB Special Judge
Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News - a newspaper chock-full of rumors, and owns the Bunkachou - her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!
During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girl x in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1, Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [Lki, Rki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What's more, Aya cannot take more than Dk photos at the k-th day. Under these constraints, the more photos, the better.
Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.
Input
There are about 40 cases. Process to the end of file.
Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1, G2, ..., Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.
Output
For each case, first output the number of photos Aya can take, -1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.
Output a blank line after each case.
Sample Input
2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 3 9
1 3 9
2 3 9 2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 0 3
1 3 6
2 6 9 2 3
12 12 12
3 15
0 3 9
1 3 9
2 3 9
3 21
0 0 3
1 3 6
2 6 12
Sample Output
36
6
6
6
6
6
6 36
9
6
3
3
6
9 -1
题意:n天给m个女孩拍照,每个女孩至少要拍gi张,每一天要给c个不同的女孩拍照,每一天最多拍d张,每一天每个女孩最少拍L张,最多拍R张
问能否完成拍照,若能输出最多拍多少张,同时输出每一天每个女孩拍多少张
否则,输出-1 有源汇上下界最大流
源点向每一天连[0,d]的边,每个女孩向汇点连[gi,inf]的边,每一天向每个女孩连[L,R]的边 本题无法评测。。,所以代码不知对错
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define N 1500
#define M 1500000
#define inf 2e9
using namespace std;
int n,m,src,dec,S,T,sum;
int tot,front[N],to[M],next[M],cap[M];
int lev[N],cur[N],a[N];
int ans[N],low[][];
queue<int>q;
void add(int u,int v,int w)
{
to[++tot]=v; next[tot]=front[u]; front[u]=tot; cap[tot]=w;
to[++tot]=u; next[tot]=front[v]; front[v]=tot; cap[tot]=;
}
bool bfs(int s,int t)
{
for(int i=;i<=n+m+;i++) cur[i]=front[i],lev[i]=-;
while(!q.empty()) q.pop();
q.push(s);
lev[s]=;
int now;
while(!q.empty())
{
now=q.front(); q.pop();
for(int i=front[now];i;i=next[i])
if(cap[i]>&&lev[to[i]]==-)
{
lev[to[i]]=lev[now]+;
if(to[i]==t) return true;
q.push(to[i]);
}
}
return false;
}
int dfs(int now,int t,int flow)
{
if(now==t) return flow;
int delta,rest=;
for(int & i=cur[now];i;i=next[i])
{
if(lev[to[i]]>lev[now]&&cap[i]>)
{
delta=dfs(to[i],t,min(flow-rest,cap[i]));
if(delta)
{
cap[i]-=delta; cap[i^]+=delta;
rest+=delta; if(rest==flow) break;
}
}
}
if(rest!=flow) lev[now]=-;
return rest;
}
int dinic(int s,int t)
{
int tmp=;
while(bfs(s,t))
tmp+=dfs(s,t,inf);
return tmp;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
tot=; sum=;
memset(a,,sizeof(a));
memset(front,,sizeof(front));
dec=n+m+; S=n+m+; T=n+m+;
add(dec,src,inf);
int x;
for(int i=;i<=m;i++)
{
scanf("%d",&x);
a[i]-=x;
a[dec]+=x;
add(i,dec,inf);
}
int c,d,y,z;
for(int i=;i<=n;i++)
{
scanf("%d%d",&c,&d);
add(src,m+i,d);
for(int j=;j<=c;j++)
{
scanf("%d%d%d",&z,&x,&y);
z++;
add(m+i,z,y-x);
low[i][z]=x;
a[m+i]-=x; a[z]+=x;
}
}
for(int i=;i<=n+m+;i++) ///i=0
if(a[i]<) add(i,T,-a[i]);
else if(a[i]>) add(S,i,a[i]),sum+=a[i];
if(dinic(S,T)==sum)
{
//int okflow=cap[3]; cap[3]=-1;
//printf("%d\n",dinic(src,dec)+okflow);
dinic(src,dec); add(dec,src,-inf);
int g=;
for(int i=front[src];i;i=next[i]) g+=cap[i^];
printf("%d\n",g);
for(int i=front[src];i;i=next[i])
{
memset(ans,,sizeof(ans));
if(to[i]<=m||to[i]>m+n) continue;
for(int j=front[to[i]];j;j=next[j])
{
if(to[j]>m) continue;
ans[to[j]]=cap[j^];
}
for(int j=;j<=m;j++) printf("%d\n",ans[j]+low[to[i]-m][j]);
}
}
else printf("-1\n");
printf("\n");
}
return ;
}
zoj 3229 Shoot the Bullet(有源汇上下界最大流)的更多相关文章
- ZOJ 3229 Shoot the Bullet(有源汇上下界最大流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 题目大意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给 ...
- ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)
题意:要在n天里给m个女生拍照,每个女生有拍照数量的下限Gi,每天有拍照数量的上限Di,每天当中每个人有拍照的上限Lij和Rij.求在满足限制的基础上,所有人最大能拍多少张照片. 分析:抛开限制,显然 ...
- zoj 3229 Shoot the Bullet(无源汇上下界最大流)
题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...
- ZOJ 3229 Shoot the Bullet | 有源汇可行流
题目: 射命丸文要给幻想乡的居民照相,共照n天m个人,每天射命丸文照相数不多于d个,且一个人n天一共被拍的照片不能少于g个,且每天可照的人有限制,且这些人今天照的相片必须在[l,r]以内,求是否有可行 ...
- 【有源汇上下界最大流】ZOJ 3229 Shoot the Bullet
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3229 题目大意: n天给m个女孩拍照(1<=n<= ...
- Shoot the Bullet(ZOJ3229)(有源汇上下界最大流)
描述 ensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utop ...
- 【有源汇上下界费用流】BZOJ 3876 [Ahoi2014]支线剧情
题目链接: http://www.lydsy.com:808/JudgeOnline/problem.php?id=3876 题目大意: 给定一张拓扑图(有向无环图),每条边有边权,每次只能从第一个点 ...
- POJ2396 Budget [有源汇上下界可行流]
POJ2396 Budget 题意:n*m的非负整数矩阵,给出每行每列的和,以及一些约束关系x,y,>=<,val,表示格子(x,y)的值与val的关系,0代表整行/列都有这个关系,求判断 ...
- 有源汇上下界可行流(POJ2396)
题意:给出一个n*m的矩阵的每行和及每列和,还有一些格子的限制,求一组合法方案. 源点向行,汇点向列,连一条上下界均为和的边. 对于某格的限制,从它所在行向所在列连其上下界的边. 求有源汇上下界可行流 ...
随机推荐
- 软件定义网络(SDN)研究进展
写在前面 这是我入门SDN以来的第一篇论文,它是一篇中文综述,看起来相对容易.也让我对SDN有了进一步的认识.下面是我的一些心得. 全文框架 SDN 将数据平面与控制平面解耦合,简化了网络管理. SD ...
- 福大软工1816:Alpha事后诸葛
福大软工·第十一次作业-Alpha事后诸葛亮 组长博客链接 本次作业博客链接 项目Postmortem 模板 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描 ...
- 严重: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"] java.lang.NullPointer
刚接触servlet类,按照课本的方法使用eclipse新建了一个servlet类. 新建完成后,在web.xml里面进行注册 这时候就会报错了. 五月 07, 2016 11:23:28 上午 or ...
- SVN版本合并技巧
公司使用了bug管理系统,项目添加新功能时,建一个主工单,再分成多个子工单,将子工单分给多个程序员来开发. 开发人员完成一部分就提交一部分,多个小功能模块就分多次提交到测试主干,然后用测试主干项目发布 ...
- Eclipse项目导入到Android Studio中
背景 最近需要将Eclipse中的android项目导入到Android Studio中!倒腾一番,记录如下! 步骤1 打开Android Studio(下文称AS),选择Import project ...
- 【C++】指针和引用
引用: 引用(reference)是为对象起了另外一个名字,引用类型应用(refers to)另外一种类型.通过将声明符写成&d的形式来定义引用类型,其中d是声明的变量名. 一般初始化变量时, ...
- ios基础动画、关键帧动画、动画组、转场动画等
概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...
- iOS----MRC(手动内存管理)
1.MRC是什么,有什么用? 在苹果开发中,我们是没有垃圾回收机制的.所以在ARC推出之前,我们苹果开发程序员需要通过手动代码的形式尽量严密的管理我们的App的内存: ---------------- ...
- BZOJ 2424 订货(贪心+单调队列)
怎么题解都是用费用流做的啊...用单调队列多优美啊. 题意:某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月初 ...
- bzoj1272 Gate Of Babylon(计数方法+Lucas定理+乘法逆元)
Description Input Output Sample Input 2 1 10 13 3 Sample Output 12 Source 看到t很小,想到用容斥原理,推一下发现n种数中选m个 ...