题目:

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


题解:

建个源点向每天连容量为[0,d],每天向每个人连[l,r],每个人向汇点连[g,INF]

我们已经建好了一个有源汇的有上下界网络

我们再从T向S连[0,INF]就变了一个无源汇!

这个时候我们套用无源汇模板即可

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define N 1505
#define M 750005
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
int ret=,neg=;char j=getchar();
for (;j>'' || j<'';j=getchar())
if (j=='-') neg=-;
for (;j>='' && j<='';j=getchar())
ret=ret*+j-'';
return ret*neg;
}
struct adj {int nxt,v,w;}e[M];
int head[N],du[N],id[][],low[][],lev[N],cur[N],dis[N];
int sum,ans,ecnt=,S,T,n,m,St,Ed;
queue <int> q;
void add(int u,int v,int w)
{
e[++ecnt].v=v;e[ecnt].w=w;e[ecnt].nxt=head[u];head[u]=ecnt;
e[++ecnt].v=u;e[ecnt].w=;e[ecnt].nxt=head[v];head[v]=ecnt;
}
void init()
{
sum=ans=;ecnt=;
memset(head,,sizeof(head));
memset(du,,sizeof(du));
memset(id,,sizeof(id));
}
bool Bfs()
{
while (!q.empty()) q.pop();
for (int i=;i<=T;i++)
cur[i]=head[i],dis[i]=-;
dis[S]=;q.push(S);
while (!q.empty())
{
int u=q.front();q.pop();
for (int i=head[u],v;i;i=e[i].nxt)
if (e[i].w && dis[v=e[i].v]==-)
{
dis[v]=dis[u]+,q.push(v);
if (v==T) return ;
}
}
return ;
}
int Dfs(int u,int flow)
{
if (u==T) return flow;
int ret=,delta;
for (int &i=cur[u],v;i;i=e[i].nxt)
if (e[i].w && dis[v=e[i].v]==dis[u]+)
{
delta=Dfs(v,min(e[i].w,flow-ret));
if (delta)
{
e[i].w-=delta;
e[i^].w+=delta;
ret+=delta;
if (ret==flow) break;
}
}
return ret;
}
int main()
{
while (scanf("%d%d",&n,&m)!=EOF && n)
{
St=m+n+,Ed=m+n+;
init();
for (int i=,w;i<=m;i++)
add(i,Ed,INF-(w=read())),du[i]-=w,du[Ed]+=w;
for (int i=m+,c,d;i<=m+n;i++)
{
c=read();d=read();
add(St,i,d);
for (int j=;j<=c;j++)
{
int t=read()+,l=read(),r=read();
add(i,t,r-l);du[i]-=l;du[t]+=l;
id[i-m][t]=ecnt;low[i-m][t]=l;
}
}
int h1=head[St],h2=head[Ed];
add(Ed,St,INF);
S=Ed+;T=S+;
for (int i=;i<=m+n+;i++)
if (du[i]>) add(S,i,du[i]),sum+=du[i];
else if (du[i]<) add(i,T,-du[i]);
while (Bfs()) ans+=Dfs(S,INF);
if (ans!=sum) puts("-1");
else
{
head[S]=head[T]=-;
head[St]=h1;head[Ed]=h2;
S=St;T=Ed;
while (Bfs()) ans+=Dfs(S,INF);
printf("%d\n",ans);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (id[i][j])
printf("%d\n",e[id[i][j]].w+low[i][j]);
}
putchar('\n');
}
return ;
}

ZOJ 3229 Shoot the Bullet | 有源汇可行流的更多相关文章

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

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

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

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

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

    题意:一个人要给女孩子们拍照,一共 n 天,m 个女孩子,每天他至多拍 d[i] 张照片,每个女孩子总共要被至少拍 g[i] 次.在第 i 天,可以拍 c[i] 个女孩子,c[i] 个女孩子中每个女孩 ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Array-快餐管饱

    一.如何获得一个数组? rsp: 1. []  2.new Array() 3.str.split() ps:new Array()可以不加括号,其传一个参数代表数组长度,两个及以上就是初始化数组. ...

  2. visual studio 2015密钥

    Visual Studio Professional 2015简体中文版(专业版)KEY:HMGNV-WCYXV-X7G9W-YCX63-B98R2Visual Studio Enterprise 2 ...

  3. Yaf学习(三)----Yaf类库Library和Model的命名规则

    1.Yaf的library和model的文件命名规则和调用 1.1在项目中,往往需要封装一些,如redis,不同的产品需要用不同的库等等等,这就涉及到封装 1.在 Yaf 中,我们可以写一个单例模式的 ...

  4. 使用SQLite删除Mac OS X 中launchpad里的快捷方式

    一般情况下,从App Store安装的应用程序,如果应用删除,那么launchpad里对应的图标会一起删除了. 而对于不是通过App Store安装的应用程序,删除应用程序,Launchpad中很可能 ...

  5. 爬虫之requests模块基础

    一.request模块介绍 1. 什么是request模块 - python中原生的基于网络请求的模块,模拟浏览器发起请求. 2. 为什么使用request模块 - urllib需要手动处理url编码 ...

  6. JavaScript 对引擎、运行时、调用堆栈的概述理解

    JavaScript 对引擎.运行时.调用堆栈的概述理解  随着JavaScript越来越流行,越来越多的团队广泛的把JavaScript应用到前端.后台.hybrid 应用.嵌入式等等领域. 这篇文 ...

  7. ts包、表、子表、section的关系

    我们经常接触到创建 DEMUX,注册 Filter 过滤数据, 通过回调过滤出 section 数据,然后我们对 section 数据做具体的解析或者其他操作. 我们这里说的 section 就是段的 ...

  8. react-router 4.0中跳转失灵

    在https://github.com/ReactTraining/history文档中,跳转是 用这种方法,但是,用了之后就存在这么一个问题,网址换了但是页面并没有刷新. 查了资料后,history ...

  9. 【转】在Ubuntu 16.10 Server 上部署 Moodle

    第一步 安装 Ubuntu 16.10 Server LTS Moodle 的官方文档肯定了Ubuntu Server LTS 是适合运维Moodle平台的. 1.使用纯代码交互的服务器Ubuntu更 ...

  10. 利尔达NB-IOT的PSM和eDRX低功耗模式笔记

    1. NB-IOT的技术优势,广覆盖,NB-IOT与GPRS和LTE相比较,最大链路预算提升了20dB,相当于提升了100倍,即使在地车车库.地下室.地下管道等普通无线网络信号难以到达的地方也容易覆盖 ...