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 ...
随机推荐
- PHP安装OPENSSL扩展模块
新项目上线时,PHP开发同事反映邮件功能不能正常使用. 原来是用465的SMTP加密端口,不是25端口.那要为当前的PHP安装OPENSSL扩展啦. 还好,网上有很多,弄一个过来就搞定. http:/ ...
- github如何删除一个repository(仓库)
昨天有人问我如何删除自己创建的一个项目,我浏览了一下github网站,确实不太容易找到删除功能.这里介绍一下啊如何在github上删除一个repository 一:首先点击进入你要删除的reposit ...
- OR扩展
<pre name="code" class="sql">SQL> select substr(xx.acct_no,1,5) agent_o ...
- BZOJ2212: [Poi2011]Tree Rotations
2212: [Poi2011]Tree Rotations Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 391 Solved: 127[Submi ...
- 2015第22周六Java反射、泛型、容器简介
Java的反射非常强大,传递class, 可以动态的生成该类.取得这个类的所有信息,包括里面的属性.方法以及构造函数等,甚至可以取得其父类或父接口里面的内容. obj.getClass().getDe ...
- cf493C Vasya and Basketball
C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Oracle 中按条件过滤重复记录
在数据处理中,经常会遇到类似这样的情况:数据库中存在多条记录,其中某些字段值相同,其他字段值不同.实际的业务需要针对这样的情况,只保留一条数据,其他数据删除.如何做到呢?在sql中有top关键字相对容 ...
- Window7下vagrant的部署
1. 下载并安装VirtualBox 下载地址:https://www.virtualbox.org/wiki/Downloads,下载最新的安装包,接下来的安装步骤就是下一步下一步了,你懂的 ...
- java基础之成员变量与局部变量
成员变量的含义 局部变量的含义 成员变量与局部变量的区别
- UIActivityIndicatorView活动控制器的大小改变
self.activityView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicat ...