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

  1. ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)

    题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...

  2. ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)

    #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...

  3. zoj3229 Shoot the Bullet(有源汇有上下界的最大流)

    题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...

  4. ZOJ3229 Shoot the Bullet [未AC]

    Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge Gensokyo is a world which exist ...

  5. zoj3229 Shoot the Bullet (有源汇最大流)

    题目大意:文文要给幻想乡的女♂孩子们拍照,一共n天,m个女♂孩子,每天文文至多拍D[i]张照片,每个女♂孩子总共要被文文至少拍G[i]次.在第i天,文文可以拍c[i]个女♂孩子,c[i]个女♂孩子中每 ...

  6. zoj 3229 Shoot the Bullet(无源汇上下界最大流)

    题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...

  7. ZOJ 3229 Shoot the Bullet [上下界最大流]

    ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...

  8. Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流

    /** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...

  9. ZOJ 3229 Shoot the Bullet

    Shoot the Bullet Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origin ...

随机推荐

  1. 局域网架个YUM源-HTTP的

    在安装CDH时,这是个绕不过去的坎. 参考URL: http://www.21ops.com/linux/26465.html 奇怪的是,我并没执行creatrepo这个,直接将光盘MOUNT来用的. ...

  2. IDA pro 的Python环境变量设置

    推荐使用IDA PRO6.1+Python2.6 安装完毕Python2.6后,添加如下的环境变量: PYTHONHOME=C:\Python26PATH=%PATH%;C:\Python26LIB= ...

  3. requireJS define require

    原文地址:http://blog.csdn.net/xiaogou56a/article/details/21340213 define 用来定义模块 require 用来加载模块 1 因为定义一个模 ...

  4. sicily 1007 To and Fro

    题意:字符串的操作处理 // Problem#: 8768 // Submission#: 2606406 // The source code is licensed under Creative ...

  5. vue-cli 脚手架总结

    > vue-cli 的脚手架项目模板有browserify 和 webpack , 现在自己在用的是webpack , 官网给出了两个模板: webpack-simple 和 webpack 两 ...

  6. UIScrollView使用autolayout 垂直滚动

    转自:http://dadage456.blog.163.com/blog/static/30310744201491141752716 1.创建一个空白的UIViewController .将UIS ...

  7. Cocos2d-x3.0游戏实例之《别救我》第二篇——创建物理世界

    这篇我要给大家介绍两个知识点: 1. 创建游戏物理世界 2. 没了(小若:我噗) 害怕了?不用操心.这太简单了~! 笨木头花心贡献.啥?花心?不呢.是用心~ 转载请注明,原文地址:http://www ...

  8. 寒哥细谈之AutoLayout全解

    文/南栀倾寒(简书作者)原文链接:http://www.jianshu.com/p/683fbcbfb705著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 看到群中好多朋友还停留在Fr ...

  9. Android开源代码解读のOnScrollListener实现ListView滚屏时不加载数据

    使用ListView过程中,如果滚动加载数据的操作比较费时,很容易在滚屏时出现屏幕卡住的现象,一个解决的办法就是不要在滚动时加载数据,而是等到滚动停止后再进行数据的加载.这同样要实现OnScrollL ...

  10. 常用的50条linux 命令

    从今天起,咱开始正式学习python了,于是遍整理了50条linux的常用命令. 1 线上查询帮助命令 :man   遇到什么不会的命令可以 man +你想要查询的命令 (需要有网),因为是英文的所以 ...