ZOJ 3229 Shoot the Bullet

题意:此生无悔入东方


上下界最大流

spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=2005, M=4e5+5, INF=1e9;
inline ll read(){
char c=getchar();ll x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
} int n, m, extra[N], s, t, tot, c, b, x, l, r;
int a[370][1005];
struct edge{int v, c, f, ne, lower;}e[M];
int cnt=1, h[N];
inline int ins(int u, int v, int c, int b=0) { //printf("ins %d %d %d %d\n",u,v,c,b);
e[++cnt]=(edge){v, c, 0, h[u], b}; h[u]=cnt;
e[++cnt]=(edge){u, 0, 0, h[v], b}; h[v]=cnt;
return cnt-1;
}
int q[N], head, tail, vis[N], d[N], cur[N];
bool bfs(int s, int t) {
memset(vis, 0, sizeof(vis));
head=tail=1;
q[tail++]=s; d[s]=0; vis[s]=1;
while(head!=tail) {
int u=q[head++];
for(int i=h[u];i;i=e[i].ne)
if(!vis[e[i].v] && e[i].c>e[i].f) {
vis[e[i].v]=1; d[e[i].v]=d[u]+1;
q[tail++]=e[i].v;
if(e[i].v == t) return true;
}
}
return false;
}
int dfs(int u, int a, int t) {
if(u==t || a==0) return a;
int flow=0, f;
for(int &i=cur[u];i;i=e[i].ne)
if(d[e[i].v]==d[u]+1 && (f=dfs(e[i].v, min(a, e[i].c-e[i].f), t))>0) {
flow+=f;
e[i].f+=f;
e[i^1].f-=f;
a-=f;
if(a==0) break;
}
if(a) d[u]=-1;
return flow;
}
int dinic(int s, int t) {
int flow=0;
while(bfs(s, t)) {
for(int i=0; i<=tot; i++) cur[i]=h[i];
flow+=dfs(s, INF, t);
}
return flow;
} int main() {
freopen("in","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF) {
s=0; t=n+m+1;
cnt=1; memset(h,0,sizeof(h)); memset(extra, 0, sizeof(extra));
for(int i=1; i<=m; i++) b=read(), ins(n+i, t, INF, b), extra[n+i]-=b, extra[t]+=b;
for(int i=1; i<=n; i++) {
a[i][0]=read();
c=read(); ins(s, i, c, 0);
for(int j=1; j<=a[i][0]; j++)
x=read()+1, l=read(), r=read(), a[i][j]=ins(i, n+x, r-l, l), extra[i]-=l, extra[n+x]+=l;
} int ss=n+m+2, tt=n+m+3, sum=0;
tot=n+m+3;
for(int i=s; i<=t; i++) {
if(extra[i] > 0) ins(ss, i, extra[i]), sum+=extra[i];
if(extra[i] < 0) ins(i, tt, -extra[i]);
}
ins(t, s, INF);
int flow=dinic(ss, tt); //printf("sum %d %d\n",sum,flow); if(flow != sum) puts("-1");
else {
printf("look %d\n",e[cnt-1].f);
//e[cnt-1]=e[cnt]=edge();
e[cnt].f=0;
printf("%d\n", dinic(s, t));
for(int i=1; i<=n; i++)
for(int j=1; j<=a[i][0]; j++) x=a[i][j], printf("%d\n", e[x].f + e[x].lower);
}
puts("");
}
return 0;
}

ZOJ 3229 Shoot the Bullet [上下界最大流]的更多相关文章

  1. ZOJ 3229 Shoot the Bullet | 有源汇可行流

    题目: 射命丸文要给幻想乡的居民照相,共照n天m个人,每天射命丸文照相数不多于d个,且一个人n天一共被拍的照片不能少于g个,且每天可照的人有限制,且这些人今天照的相片必须在[l,r]以内,求是否有可行 ...

  2. 【有源汇上下界最大流】ZOJ 3229 Shoot the Bullet

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3229 题目大意: n天给m个女孩拍照(1<=n<= ...

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

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 题目大意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给 ...

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

    Shoot the Bullethttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 Time Limit: 2 Second ...

  5. ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)

    题意:要在n天里给m个女生拍照,每个女生有拍照数量的下限Gi,每天有拍照数量的上限Di,每天当中每个人有拍照的上限Lij和Rij.求在满足限制的基础上,所有人最大能拍多少张照片. 分析:抛开限制,显然 ...

  6. ZOJ 3229 Shoot the Bullet(有源汇的上下界最大流)

    Description Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It ...

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

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

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

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

  9. ZOJ 3229 Shoot the Bullet

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

随机推荐

  1. 最长上升子序列(LIS经典变型) dp学习~5

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  2. 重新学习一次javascript;

    每次有项目的时候,总觉得自己什么都不会做,然后做的时候又很简单,一会就做完了,啪啪打脸: 每次别人问的时候,我知道怎么做,但是不知道具体原理,觉得瞬间low了: 想要好好的吧基础掌握一下: 这几天空闲 ...

  3. 010 有顺序的Map的实现类:TreeMap和LinkedHashMap

    作者:nnngu GitHub:https://github.com/nnngu 博客园:http://www.cnblogs.com/nnngu 简书:https://www.jianshu.com ...

  4. [国嵌攻略][060][LCD工作原理解析]

    LCD硬件体系 1.LCD液晶屏 液晶属于一种有机化合物,分子形状为长棒状,在不同的电流作用下,分子会有规律旋转,这样对光线产生一定的控制形成一个像素,而很多像素右可以构成完整的图像. LCD是Liq ...

  5. IE8兼容border-radius.

    我们知道,CSS3新增的很多简洁优美的属性,比如border-radius.box-shadow.border-image.gradients.RGBA...因为这些属性的出现,我们可以很方便的就写会 ...

  6. JAR包介绍大全用途作用详解JAVA

    jta.jar 标准JTA API必要commons-collections.jar 集合类 必要antlr.jar  ANother Tool for Language Recognition 必要 ...

  7. HTML <form>标签

    1.单选按钮 <html> <body> <form> 名: <input type="radio" name="myname& ...

  8. DALI 2.0解码模块

    DALI2.0调光解码模块使用手册 一.概述(联系人:张先生,电话:13923882807,QQ:813267849) 欢迎使用本公司的DALI 2.0解码模块,该模块支持"DALI第二套协 ...

  9. 【js 实践】js 实现木桶布局

    还有两个月左右就要准备实习了,所以特意练一练,今天终于搞定了js 的木桶布局了 这一个是按照一个插件的规格去写的以防以后工作需要,详细的解释在前端网这里 http://www.qdfuns.com/n ...

  10. [转]CentOS Apache 性能调试!

    查看Apache的并发请求数及其TCP连接状态: netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 返回结果示例 ...