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. hbmy周赛1--D

    D - Toy Cars Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  2. [图像类名词解释][ RGB YUV HSV相关解释说明]

    一.概述 颜色通常用三个独立的属性来描述,三个独立变量综合作用,自然就构成一个空间坐标,这就是颜色空间.但被描述的颜色对象本身是客观的,不同颜色空间只是从不同的角度去衡量同一个对象.颜色空间按照基本机 ...

  3. Java的语言特点详解

    1)简单性:java从C++简化而来,设计者们把C++语言中许多可用的特征去掉了,这些特征是一般程序员很少使用的.java还剔除了C++操作符过载和指针操作. 2)面向对象:java是一个面向对象的语 ...

  4. JavaScript八张思维导图—字符串用法

    JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...

  5. Git的简单的基本使用

    前言: 接触了Android Studio,自然是知道了Github这个网站,这个网站有许多大神们做的开源库,我们只需要简单地引入就是可以使用到这些开源库从而实现酷炫的效果,最近也是刚接触到Git的使 ...

  6. 一键批量打印EXCEL、WORD文档

    一键批量打印EXCEL.WORD文档,本方法也可以打印同一个文档N份,可以批量打印A3.A4文档,包括单.双面打印等.希望能帮到广大朋友.请大家注重原创版权,不得在未经许可的下转载.传播,或者用来对同 ...

  7. Html5+js测试题(开发版)

    ------------------------------------------------ 1. 谈谈你对js闭包的理解: 使用闭包主要是为了设计私有的方法和变量.闭包的优点是可以避免全局变量的 ...

  8. eclipse 按住ctrl 按钮没有反映

    以下是修改为XML Editior打开方法Window -> Preferences -> General -> Editors -> File Associations Fi ...

  9. Java数据持久层框架 MyBatis之背景知识二

    对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.org/mybatis-3/zh/index.html 对于语言的学习而言,马上上手去编程,多多练习 ...

  10. js截取字符串的方法

    1,slice(a, b) 第一个参数表示起始位置,第二个表示截取到但不包含 关于参数正负问题,只要记住一点:永远不能倒着截取!否则返回空字符串 2,substring(a, b) 第一个参数表示起始 ...