博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 3229 Shoot the Bullet(有源汇上下界最大流)
阅读量:5925 次
发布时间:2019-06-19

本文共 5679 字,大约阅读时间需要 18 分钟。

Shoot the Bullet

Time Limit: 2 Seconds     
Memory Limit: 32768 KB     
Special Judge

Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News - a newspaper chock-full of rumors, and owns the Bunkachou - her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!

 

During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girl x in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1, Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [Lki, Rki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What's more, Aya cannot take more than Dk photos at the k-th day. Under these constraints, the more photos, the better.

Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.

Input

There are about 40 cases. Process to the end of file.

Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1, G2, ..., Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.

Output

For each case, first output the number of photos Aya can take, -1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.

Output a blank line after each case.

Sample Input

2 312 12 123 180 3 91 3 92 3 93 180 3 91 3 92 3 92 312 12 123 180 3 91 3 92 3 93 180 0 31 3 62 6 92 312 12 123 150 3 91 3 92 3 93 210 0 31 3 62 6 12

Sample Output

3666666636963369-1 题意:n天给m个女孩拍照,每个女孩至少要拍gi张,每一天要给c个不同的女孩拍照,每一天最多拍d张,每一天每个女孩最少拍L张,最多拍R张 问能否完成拍照,若能输出最多拍多少张,同时输出每一天每个女孩拍多少张 否则,输出-1 有源汇上下界最大流 源点向每一天连[0,d]的边,每个女孩向汇点连[gi,inf]的边,每一天向每个女孩连[L,R]的边 本题无法评测。。,所以代码不知对错
#include
#include
#include
#include
#define N 1500#define M 1500000#define inf 2e9using namespace std;int n,m,src,dec,S,T,sum;int tot,front[N],to[M],next[M],cap[M];int lev[N],cur[N],a[N];int ans[N],low[370][1001];queue
q;void add(int u,int v,int w){ to[++tot]=v; next[tot]=front[u]; front[u]=tot; cap[tot]=w; to[++tot]=u; next[tot]=front[v]; front[v]=tot; cap[tot]=0;}bool bfs(int s,int t){ for(int i=0;i<=n+m+3;i++) cur[i]=front[i],lev[i]=-1; while(!q.empty()) q.pop(); q.push(s); lev[s]=0; int now; while(!q.empty()) { now=q.front(); q.pop(); for(int i=front[now];i;i=next[i]) if(cap[i]>0&&lev[to[i]]==-1) { lev[to[i]]=lev[now]+1; if(to[i]==t) return true; q.push(to[i]); } } return false;}int dfs(int now,int t,int flow){ if(now==t) return flow; int delta,rest=0; for(int & i=cur[now];i;i=next[i]) { if(lev[to[i]]>lev[now]&&cap[i]>0) { delta=dfs(to[i],t,min(flow-rest,cap[i])); if(delta) { cap[i]-=delta; cap[i^1]+=delta; rest+=delta; if(rest==flow) break; } } } if(rest!=flow) lev[now]=-1; return rest;}int dinic(int s,int t){ int tmp=0; while(bfs(s,t)) tmp+=dfs(s,t,inf); return tmp;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { tot=1; sum=0; memset(a,0,sizeof(a)); memset(front,0,sizeof(front)); dec=n+m+1; S=n+m+2; T=n+m+3; add(dec,src,inf); int x; for(int i=1;i<=m;i++) { scanf("%d",&x); a[i]-=x; a[dec]+=x; add(i,dec,inf); } int c,d,y,z; for(int i=1;i<=n;i++) { scanf("%d%d",&c,&d); add(src,m+i,d); for(int j=1;j<=c;j++) { scanf("%d%d%d",&z,&x,&y); z++; add(m+i,z,y-x); low[i][z]=x; a[m+i]-=x; a[z]+=x; } } for(int i=0;i<=n+m+1;i++) ///i=0 if(a[i]<0) add(i,T,-a[i]); else if(a[i]>0) add(S,i,a[i]),sum+=a[i]; if(dinic(S,T)==sum) { //int okflow=cap[3]; cap[3]=-1; //printf("%d\n",dinic(src,dec)+okflow); dinic(src,dec); add(dec,src,-inf); int g=0; for(int i=front[src];i;i=next[i]) g+=cap[i^1]; printf("%d\n",g); for(int i=front[src];i;i=next[i]) { memset(ans,0,sizeof(ans)); if(to[i]<=m||to[i]>m+n) continue; for(int j=front[to[i]];j;j=next[j]) { if(to[j]>m) continue; ans[to[j]]=cap[j^1]; } for(int j=1;j<=m;j++) printf("%d\n",ans[j]+low[to[i]-m][j]); } } else printf("-1\n"); printf("\n"); } return 0;}

 

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/6766773.html

你可能感兴趣的文章
Arcpy的使用总结a
查看>>
人工智能AI,到底可以做什么?Face To
查看>>
CentOS系统时间与UTC时间不一致的解决方法
查看>>
干货|可视化分析 web 访问日志
查看>>
Introduction to Elasticsearch in PHP
查看>>
如何拦截网路突发性垃圾邮件
查看>>
数据库并发的五个问题以及四级封锁协议与事务隔离的四个级别
查看>>
Android 如何连真机测试
查看>>
linux-裁剪Linux功能,编译/bin/login, busybox编译linux
查看>>
PLC编程入门
查看>>
个人读书清单
查看>>
HTML骨架结构
查看>>
Intellij下的android实践
查看>>
QQ拼音直接提权WIN8
查看>>
用FPM打RPM包
查看>>
度量时间差
查看>>
4.python的迭代器与生成器
查看>>
8. 队列(3)
查看>>
yum 安装apache php mysql
查看>>
User Profile文件变Temp
查看>>