Shoot the Bullet

Time Limit: 2000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 3229
64-bit integer IO format: %lld      Java class name: Main

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, Tk1Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [LkiRki], 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, G1G2, ..., 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 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 3 9
1 3 9
2 3 9 2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 0 3
1 3 6
2 6 9 2 3
12 12 12
3 15
0 3 9
1 3 9
2 3 9
3 21
0 0 3
1 3 6
2 6 12

Sample Output

36
6
6
6
6
6
6 36
9
6
3
3
6
9 -1

External Links


Wikipedia
Touhou Wiki

 

Source

Author

WU, Zejun
 
解题:有源上下界流
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
};
int head[maxn],d[maxn],cur[maxn],tot,n,m,S,T;
arc e[];
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof(d));
d[S] = ;
q.push(S);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[e[i].to] == d[u] + && (a=dfs(e[i].to,min(e[i].flow,low)))){
tmp += a;
low -= a;
e[i].flow -= a;
e[i^].flow += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int tmp = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
tmp += dfs(S,INF);
}
return tmp;
}
int de[maxn],pos[][maxn],low[][maxn];
int main() {
int gs,day,dayup,ith,down,up;
while(~scanf("%d %d",&n,&m)){
memset(head,-,sizeof(head));
memset(de,,sizeof(de));
memset(low,-,sizeof(low));
int full = tot = ;
for(int i = ; i <= m; i++){
scanf("%d",&gs);
add(n+i,n+m+,INF-gs);//女孩到汇点
de[n+i] -= gs;
de[n+m+] += gs;
}
for(int i = ; i <= n; i++){
scanf("%d %d",&day,&dayup);
add(,i,dayup);
for(int j = ; j <= day; j++){
scanf("%d %d %d",&ith,&down,&up);
pos[i][++ith] = tot;//第i天第ith个女孩
add(i,n+ith,up-down);//转化
de[i] -= down;
de[n+ith] += down;
low[i][ith] = down;
}
}
add(n+m+,,INF);
S = n+m+;
T = n+m+;
for(int i = ; i <= n + m + ; i++){
if(de[i] > ){
full += de[i];
add(S,i,de[i]);
}
if(de[i] < ) add(i,T,-de[i]);
}
if(dinic() == full){
S = ;
T = n + m + ;
printf("%d\n",dinic());
for(int i = ; i <= n; i++){
for(int j = ; j <= m; j++)
if(low[i][j] > -) printf("%d\n",low[i][j] + e[pos[i][j]^].flow);
} }else puts("-1");
puts("");
}
return ;
}

ZOJ 3229 Shoot the Bullet的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. ZOJ 3229 Shoot the Bullet | 有源汇可行流

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

随机推荐

  1. Linux学习笔记——例说makefile 索引博文

    0.前言     从学习C语言開始就慢慢開始接触makefile.查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...

  2. iWatch报错: Authorization request cancled

    iWatch报错: Optional (Error Domin = com.apple.healthkit Code = 5 "Autherization request canceled& ...

  3. 局部变量,全局变量,extend,static

    main.c #include <stdio.h> #include "zs.h" /* 局部变量是定义在函数.代码块.函数形参列表.存储在栈中,从定义的那一行开始作用 ...

  4. 搜索分析(DFS、BFS、递归、记忆化搜索)

    搜索分析(DFS.BFS.递归.记忆化搜索) 1.线性查找 在数组a[]={0,1,2,3,4,5,6,7,8,9,10}中查找1这个元素. (1)普通搜索方法,一个循环从0到10搜索,这里略. (2 ...

  5. B1237 [SCOI2008]配对 贪心 + dp

    我刚开始,我打眼一看:哇!网络流大水题,直接费用流板子,建边跟zz一样.结果看了一眼数据范围...gg,luogu上只能得30,直接建边就是n^2,1e5根本过不了.咋办,只能另谋出路.想不出来,看题 ...

  6. N数码问题的启发式搜索算法--A*算法python实现

    一.启发式搜索:A算法 1)评价函数的一般形式 : f(n) = g(n) + h(n) g(n):从S0到Sn的实际代价(搜索的横向因子) h(n):从N到目标节点的估计代价,称为启发函数(搜索的纵 ...

  7. C++中值传递(pass-by-value)和引用传递(pass-by-reference)

    1.pass-by-value的情况: 缺省情况C++以pass-by-value(继承C的方式)传递对象至(或来自)函数.函数参数都是以实际参数的复件为初值,调用端所获得的也是函数返回值的一个复件, ...

  8. 软件需求规范说明 (Software Requirements Specification, 简称SRS)

    GB/T 9385-2008 笔记 为了形成确定和完备的规格说明, 我们需要明确 软件的顾客希望得到什么; 软件的供方理解用户想要什么; 4.2 SRS的基本性质 SRS是对在具体环境中执行确定功能的 ...

  9. python - 中文打印报错SyntaxError: Non-ASCII character '\xe4' in file test.py on line 3, but no encoding declared。

    python中默认的编码格式是ASCII格式, 所以在没修改编码格式时无法正确打印汉字. 解决办法: 在以后的每一个需要显示汉字的python文件中, 可以采用如下方法在 #!/usr/bin/pyt ...

  10. 利用jquery的ajaxPrefilter阻止重复发送请求

    利用jquery的ajaxPrefilter阻止重复发送请求 (function ($) { var pendingRequests = {}; // 所有ajax请求的通用前置filter $.aj ...