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 ...
随机推荐
- WCF 基于Cookie的登录验证回传问题的解决
参考资料: http://www.cnblogs.com/czcz1024/p/3333138.html http://megakemp.com/2009/02/06/managing-shared- ...
- Linux 让进程在后台可靠运行的几种方法
我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...
- java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
出现java cannot find the tag library descriptor for "http://java.sun.com/jsp/jstl/core" 主要的愿 ...
- AzCopy – 上传/下载 Windows Azure Blob 文件
在我们收到的请求中,有一个频繁出现的请求是提供一种能在 Windows Azure Blob 存储与其本地文件系统之间轻松上传或下载文件的方法.一年半前, 我们很高兴地发布了 AzCopy, Wind ...
- java.lang.ClassNotFoundException错误原因汇总
开发java很长时间了,还经常会遇到java.lang.ClassNotFoundException这样的错误,最近又处理了一次,起初怀疑是jdk版本比class文件的编译版本低了导致了,但是运维人员 ...
- hdu5023--A Corrupt Mayor's Performance Art
来源:2014 ACM/ICPC Asia Regional Guangzhou Online 题意:长度为n的一个线段,1-30为颜色代号.初始状态每个单位长度颜色都为2,然后有q次操作,P操作把区 ...
- 常用的js对象扩展方法
1. 字符串的replaceAll String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) { if (!R ...
- ashx实现文件下载以及文件MD5码测试
cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System ...
- ncsim仿真VHDL
ncsim仿真VHDL 1.文件列表 ctrl.vhd design_io.vhd tb.vhd compile.nc simulate.nc ./shm/shmtb.tcl 2. Compile你的 ...
- java基础之String
字符串的含义 字符串的应用 字符串的方法