ZOJ 3229 Shoot the Bullet [上下界最大流]
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 [上下界最大流]的更多相关文章
- ZOJ 3229 Shoot the Bullet | 有源汇可行流
题目: 射命丸文要给幻想乡的居民照相,共照n天m个人,每天射命丸文照相数不多于d个,且一个人n天一共被拍的照片不能少于g个,且每天可照的人有限制,且这些人今天照的相片必须在[l,r]以内,求是否有可行 ...
- 【有源汇上下界最大流】ZOJ 3229 Shoot the Bullet
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3229 题目大意: n天给m个女孩拍照(1<=n<= ...
- ZOJ 3229 Shoot the Bullet(有源汇上下界最大流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 题目大意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给 ...
- zoj 3229 Shoot the Bullet(有源汇上下界最大流)
Shoot the Bullethttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 Time Limit: 2 Second ...
- ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)
题意:要在n天里给m个女生拍照,每个女生有拍照数量的下限Gi,每天有拍照数量的上限Di,每天当中每个人有拍照的上限Lij和Rij.求在满足限制的基础上,所有人最大能拍多少张照片. 分析:抛开限制,显然 ...
- ZOJ 3229 Shoot the Bullet(有源汇的上下界最大流)
Description Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It ...
- Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流
/** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...
- zoj 3229 Shoot the Bullet(无源汇上下界最大流)
题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...
- ZOJ 3229 Shoot the Bullet
Shoot the Bullet Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origin ...
随机推荐
- 微信小程序监听input输入并取值
小程序的事件分为两种,冒泡和非冒泡事件,像<form/>的submit事件,<input/>的input事件,<scroll-view/>的scroll事件等非冒泡 ...
- js根据出生年月日换算年龄
function age_Conversion(date) { debugger var age = ''; var str = date.replace(/年|月/g, "-") ...
- rexray在CentOS上不能创建ceph rbd的docker volume问题定位
背景 我们通过docker的rexray插件来创建ceph rbd设备的docker volume,但总提示创建失败. # docker volume create --driver=rexray - ...
- cesium编程入门(七)3D Tiles,模型旋转
cesium编程入门(七)3D Tiles,模型旋转 上一节介绍了3D Tiles模型的位置移动,和贴地的操作,这一节来聊一聊模型的旋转, 参考<WebGl编程指南>的第四章 假设在X轴和 ...
- radiobutton独特属性
radiobutton是通过name来分组的,也就是说,使用相同的名字的radio,它们才是单选的,如果名字不同的radio,是不具备这个效果的,这个是第一要点. 第二,针对不同的radio(name ...
- 数据结构与算法(1)----->排序
这一版块,把必备的数据结构和算法做一个总结!包括排序.队列.链表.二叉树.排组合,动态规划....... 总结的过程包括理论部分,练题目可以自己去leetcode/牛客网刷起来- 第一篇文章讲排序- ...
- 算法,java代码实现打印万年历
万年历 以1900年1月1号星期一为时间原点 星期日 第一天 星期一 第二天 星期二 第三天 星期三 第四天 星期四 第五天 星期五 第六天 星期六 第七天 1.计算出当前日 ...
- java使用Websocket获取HttpSession出现的问题与解决
websocket的写法就不多说了,主要记一记其中出现的问题 1.获取不到httpSession 解决办法:先重写握手方法,将httpsession放入ServerEndpointConfig.get ...
- Linq 实例
1.分页 ).Take(); 2.分组 1)一般分组 //根据顾客的国家分组,查询顾客数大于5的国家名和顾客数var 一般分组 = from c in ctx.Customers group c by ...
- redis常见命令使用
这篇经验主要介绍了Redis常见用的一些操作命令.这篇例子是在windows上操作的.linux类似.写的一些基础,大神就别看了. 工具/原料 redis windows 方法/步骤 1 可以 ...