ZOJ3229 Shoot the Bullet
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20756
思路:就讲一下有源汇上下界最大流的做法吧!对于所有的边,就按照无源汇的做法做,然后建一条(t->s,inf)的边,然后先算ss到tt的最大流,看是否满足下界,然后不管这个流的答案,清空cnt和dis,然后算出s->t的最大流,就是答案。
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#define inf 0x7fffffff
int dn[],id[];
int tot,go[],next[],first[],flow[];
int n,m,du[],op[],cnt[],dis[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void insert(int x,int y,int z){
tot++;
go[tot]=y;
next[tot]=first[x];
first[x]=tot;
flow[tot]=z;
}
void add(int x,int y,int z){
insert(x,y,z);op[tot]=tot+;
insert(y,x,);op[tot]=tot-;
}
int dfs(int x,int f,int S,int T,int nodes){
int mn=nodes,sum=;
if (x==T) return f;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (flow[i]&&dis[pur]+==dis[x]){
int F=std::min(flow[i],f-sum);
int save=dfs(pur,F,S,T,nodes);
sum+=save;
flow[i]-=save;
flow[op[i]]+=save;
if (sum==f||dis[S]>=nodes) return sum;
}
if (flow[i]) mn=std::min(mn,dis[pur]);
}
if (sum==){
cnt[dis[x]]--;
if (cnt[dis[x]]==){
dis[S]=nodes;
}else{
dis[x]=mn+;
cnt[dis[x]]++;
}
}
return sum;
}
int mxflow(int S,int T,int nodes){
int res=;
for (int i=;i<=nodes;i++) cnt[i]=dis[i]=;
while (dis[S]<nodes)
res+=dfs(S,inf,S,T,nodes);
return res;
}
int main(){
freopen("tx.in","r",stdin);
int Nodes=;
while (~scanf("%d%d",&n,&m)){
for (int i=;i<=Nodes;i++) first[i]=du[i]=;tot=;
int s=n+m+,t=s+;
int ss=t+,tt=ss+;
for (int i=;i<=m;i++){
int x=read();
du[i]-=x;
du[t]+=x;
add(i,t,inf);
}
int Cnt=;
for (int i=;i<=n;i++){
int c=read(),d=read();
add(s,i+m,d);
while (c--){
int x=read(),l=read(),r=read();
du[i+m]-=l;
du[x+]+=l;
dn[++Cnt]=l;id[Cnt]=tot+;
add(i+m,x+,r-l);
}
}
int sum=;
for (int i=;i<=t;i++)
if (du[i]>) add(ss,i,du[i]),sum+=du[i];
else add(i,tt,-du[i]);
add(t,s,inf);
if (sum!=mxflow(ss,tt,tt)) puts("-1");
else{
printf("%d\n",mxflow(s,t,tt));
for (int i=;i<=Cnt;i++)
printf("%d\n",dn[i]+flow[op[id[i]]]);
}
puts("");
Nodes=tt;
}
}
**,没看到可能有多解,害我调了好久。。
ZOJ3229 Shoot the Bullet的更多相关文章
- ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)
题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...
- ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)
#pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...
- zoj3229 Shoot the Bullet(有源汇有上下界的最大流)
题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...
- ZOJ3229 Shoot the Bullet [未AC]
Time Limit: 2 Seconds Memory Limit: 32768 KB Special Judge Gensokyo is a world which exist ...
- zoj3229 Shoot the Bullet (有源汇最大流)
题目大意:文文要给幻想乡的女♂孩子们拍照,一共n天,m个女♂孩子,每天文文至多拍D[i]张照片,每个女♂孩子总共要被文文至少拍G[i]次.在第i天,文文可以拍c[i]个女♂孩子,c[i]个女♂孩子中每 ...
- zoj 3229 Shoot the Bullet(无源汇上下界最大流)
题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...
- ZOJ 3229 Shoot the Bullet [上下界最大流]
ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...
- Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流
/** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...
- ZOJ 3229 Shoot the Bullet
Shoot the Bullet Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origin ...
随机推荐
- Unity脚本的生命周期中几个重要的方法
1.function Update () {} 正常更新,用于更新逻辑.此方法每帧都会由系统自动调用一次.2.function LateUpdate () {} 推迟更新,此方法在Update() 方 ...
- 常用的Windows批处理
切换执行路径 如果不换盘的话:cd xxx换盘:cd /d xxx 获取当前日期 编写Windows批处理时经常会需要使用到日期和时间作为文件名,所以是非常重要的. 如何获取日期呢?格式: ...
- VC的话有必要认真听,但却不用急着照办
本文来自著名风险投资人 Fred Wilson 的博客 AVC,他在 2016 年 8 月 23 日的这篇文章<Understanding VCs>里用简单的语言揭秘了 VC(风险投资人) ...
- BZOJ1978: [BeiJing2010]取数游戏 game
1978: [BeiJing2010]取数游戏 game Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 650 Solved: 400[Submit] ...
- (转载)tarjan求割点
割点是无向图中去掉后能把图割开的点.dfs时用dfn(u)记录u的访问时间,用low(u)数组记录u和u的子孙能追溯到的最早的节点(dfn值最小).由于无向图的dfs只有回边和树边,且以第一次dfs时 ...
- EucOne调试
~/.ssh/id_rsa权限问题,造成ssh无法登陆问题解决;
- 第34讲 UI组件之 ProgressDialog和Message
第34讲UI组件之 ProgressDialog和Message 1.进度对话框 ProgressDialog <1>简介 ProgressDialog是AlertDialog类的一个扩展 ...
- jQuery 遍历 json 方法大全
1.for循环: var obj = { "status":1, "bkmsg":"\u6210\u529f", "bkdata& ...
- hdu 4055 Number String(dp)
Problem Description The signature of a permutation is a string that is computed as follows: for each ...
- dom4j解析接口使用SOAP传递的xml
xml 文件的格式类型: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope ...