zoj3229:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442

题意:一个摄影师,在n天内给m个女神拍照。每个女神至少要拍Gi张照片,每一天只能给Ci个女神照相,每一天只能只能拍Di张照片,并且每个女神每天被拍的数量在[l,r]之间。问是否存在一种方案,满足条件,如果满足,最多可以照多少照片。

题解:这是一条有源汇的有上下界的最大流。首先源点s,t,源点和每一天i建立一边,上界为Di,下界为0,每个女神和t建立一边,上界是无穷,下界是Gi,因为上界是无穷大,所以下界等同为0,然后是每一天与对应的女神之间就是流量范围是[l,r],这里就可以转化成有上下界的流量处理,最后t-->s建立一边,容量是INF,这样就转化成无汇源的可行流。接下就是设超级源点ss,超级会点tt,把上面的图按照可行流的求解方式来求解。如果所有ss的出边都是满流,则有可行解。然后再跑一边最大流,此时源点时s,t,这里不再是超级源点ss,和会点tt。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 1000000000
const int N=;
struct Node {
int c;
int f;
}map[N][N];
int sx,ex,n,m;
int pre[N];
int du[N],down[N][N];
bool BFS(int x) { //BFS搜索层次网络
memset(pre,,sizeof(pre));
queue< int > Q;
Q.push(sx);
pre[sx]=;
while(!Q.empty()) {
int d=Q.front();
Q.pop();
for(int i=; i<=x; i++) {
if(!pre[i]&&map[d][i].c-map[d][i].f) {
pre[i]=pre[d]+;
Q.push(i);
}
}
}
return pre[ex]!=;
}
int dinic(int pos,int flow,int x) { //pos是顶点号,flow是当前顶点所能得到的流量,一次dinic只能求出一次增加的流量,
int f=flow;
if(pos==ex)
return flow;
for(int i=; i<=x; i++) {
if(map[pos][i].c-map[pos][i].f&&pre[pos]+==pre[i]) {
int a=map[pos][i].c-map[pos][i].f;
int t=dinic(i,min(a,flow),x);
map[pos][i].f+=t;
map[i][pos].f-=t;
flow-=t;
if(flow<=)break;
//我最开始就是这里没弄明白,我不明白为什么要此顶点得到的流量减去改变量;
//答案就在下面的 return f-flow;
}
}
if(f-flow<=)pre[pos]=-;
return f-flow;//其实这里返回给他前一层的就是这个t;因为t在层函数里面都有,所以所过避免重复就写成这样;
}
int solve(int x){
int sum=;
while(BFS(x)) {
sum+=dinic(sx,INF,x);
}
return sum;
}
int main() {
int u,v,w,t1,t2,t3;
while(~scanf("%d%d",&n,&m)) {
int s=m+n+,t=s+;
sx=t+,ex=sx+;
memset(map,,sizeof(map));
memset(du,,sizeof(du));
memset(down,-,sizeof(down));
for(int i=;i<=m; i++) {
scanf("%d",&w);
du[i]-=w;
du[t]+=w;
map[i][t].c+=INF;
}
for(int i=;i<=n;i++){
scanf("%d%d",&u,&v);
map[s][i+m].c+=v;
while(u--){
scanf("%d%d%d",&t1,&t2,&t3);
du[t1+]+=t2;
du[i+m]-=t2;
down[i+m][t1+]=t2;
map[i+m][t1+].c+=(t3-t2);
}
}
map[t][s].c=INF;
int sum=;
for(int i=;i<=t;i++){
if(du[i]>){
map[sx][i].c+=du[i];
sum+=du[i];
}
else{
map[i][ex].c+=(-du[i]);
}
}
if(solve(n+m+)!=sum)puts("-1");
else{
sx=s,ex=t;
printf("%d\n",solve(n+m+));
for(int i=m+;i<=n+m;i++){
for(int j=;j<=m;j++){
if(down[i][j]>=){
printf("%d\n",map[i][j].f+down[i][j]);
}
}
}
}
puts("");
}
return ;
}

Shoot the Bullet的更多相关文章

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

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

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

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

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

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

  4. ZOJ 3229 Shoot the Bullet

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

  5. ZOJ Problem Set - 3229 Shoot the Bullet 【有上下界网络流+流量输出】

    题目:problemId=3442" target="_blank">ZOJ Problem Set - 3229 Shoot the Bullet 分类:有源有汇 ...

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

    有源汇带上下界最大流 在原图基础上连一条汇点到源点流量为inf的边,将有源汇网络流转化为无源汇网络流用相同方法判断是否满流,如果满流再跑一边源点到汇点的最大流就是答案 例题:Shoot the Bul ...

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

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

  8. ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)

    题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...

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

    #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...

随机推荐

  1. android 74 下载文本

    页面: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...

  2. Btrace

    http://www.iteye.com/topic/1005918 背景 周五下班回家,在公司班车上觉得无聊,看了下btrace的源码(自己反编译). 一些关于btrace的基本内容,可以看下我早起 ...

  3. 如何调试PHP的Core之获取基本信息 --------风雪之隅 PHP7核心开发者

    http://www.laruence.com/2011/06/23/2057.html https://github.com/laruence PHP开发组成员, Zend兼职顾问, PHP7核心开 ...

  4. CentOS 更新yum源

    公司买了一台刀片机服务器,安装的系统版本太低,导致yum源不合适,安装就会报错. 在网上找了好长时间,才发现是yum源的问题.   转载原文: 突然想起试试 Docker,在一台计算机上安装了 Cen ...

  5. Div+css中ul ol li dl dt dd使用

    ol 有序列表.<ol><li>……</li><li>……</li><li>……</li></ol>表现 ...

  6. WPF学习之资源-Resources

    WPF学习之资源-Resources WPF通过资源来保存一些可以被重复利用的样式,对象定义以及一些传统的资源如二进制数据,图片等等,而在其支持上也更能体现出这些资源定义的优越性.比如通过Resour ...

  7. VS2015+TFS2015源代码管理

    使用Visual Studio连接TFS

  8. 使用Github建立个人博客

    总的说来 这个当有node.js 和gitbub的账号后,搭建一个自己的博客,想想还是挺美的事! 由于要把整个流程说清楚 估计lz还没这个实力,所以都是继承前辈们的经验,自己再添加一点遇到的问题和解决 ...

  9. Linux中nat模式上不了网的问题怎么解决?

    我是这么解决的

  10. CodeSmith中SchemaExplorer属性的介绍

    CodeSmith与数据库的联系,在CodeSmith中自带一个程序集SchemaExplorer.dll,这个程序集中的类主要用于获取数据库中各种对象的结构. <%@ Property Nam ...