ZOJ3229 Shoot the Bullet [未AC]
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 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
图论 网络流
复习了一波有上下界网络流的姿势。
顺便复习了一下东方的设定
题面里的罗马音居然都能看懂,是该说新标日姿势没忘光呢还是四斋蒸鹅心呢
如何求带上下界的最大流?
在求出可行流以后,删掉超级源汇,从旧源到旧汇跑网络流,把能用的残余流量都流掉,再加上原先的下界即可。
好像这道题的SPJ挂掉了,近几个月的提交结果全是Judge Internal Error
代码不保证正确,仅供参考
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt,f;
}e[mxn<<];
int hd[mxn],mct=;
inline void add_edge(int u,int v,int f){
e[++mct].v=v;e[mct].nxt=hd[u];e[mct].f=f;hd[u]=mct;return;
}
inline void insert(int u,int v,int f){
// printf("ins:%d %d %d\n",u,v,f);
add_edge(u,v,f);add_edge(v,u,);
}
int ST,ED,S,T;
int n,m;
queue<int>q;
int d[mxn];
bool BFS(){
for(int i=;i<=ED;i++)d[i]=;
q.push(ST);
d[ST]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && !d[v]){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[ED];
}
int cur[mxn];
int DFS(int u,int lim){
if(u==ED)return lim;
int f=,tmp;
for(int &i=cur[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && d[v]==d[u]+ && (tmp=DFS(v,min(lim,e[i].f)))){
e[i].f-=tmp;
e[i^].f+=tmp;
lim-=tmp;
f+=tmp;
if(!lim)return f;
}
}
d[u]=;
return f;
}
int Dinic(){
int res=,flow=;
while(BFS()){
for(int i=;i<=ED;i++)cur[i]=hd[i];
while(flow=DFS(ST,INF))res+=flow;
}
return res;
}
//
int du[mxn];
int D[mxn];
int down[][];
bool vis[][];
int id[][];
void solve_MX(){
int i,j;
ST=S;ED=T;
int ans=Dinic();
for(i=;i<=n;i++){
for(j=hd[i];j;j=e[j].nxt){
int v=e[j].v;
if(v>n && v<T){
down[i][v-n]+=e[j^].f;
}
}
}
printf("%d\n",ans);
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(vis[i][j])
printf("%d\n",down[i][j]);
}
}
return;
}
void init(){
memset(hd,,sizeof hd);mct=;
memset(vis,,sizeof vis);
memset(du,,sizeof du);
return;
}
int main(){
freopen("in.txt","r",stdin);
int i,j;
while(scanf("%d%d",&n,&m)!=EOF){
init();
S=;T=n+m+;ST=T+;ED=ST+;
int u,v,w,L,R;
for(i=;i<=m;i++){
w=read();
du[i+n]-=w;
du[T]+=w;
insert(i+n,T,INF-w);
}
for(i=;i<=n;i++){
int C=read();D[i]=read();
insert(S,i,D[i]);
for(j=;j<=C;j++){
v=read()+;L=read();R=read();
du[i]-=L;
du[v+n]+=L;
down[i][v]=L;
vis[i][v]=;
insert(i,v+n,R-L);
id[i][v]=mct;
}
}
insert(T,S,INF);
int smm=;
for(i=S;i<=T;i++){
if(du[i]>)smm+=du[i],insert(ST,i,du[i]);
else insert(i,ED,-du[i]);
}
int res=Dinic();//printf("res:%d smm:%d\n",res,smm);
if(res!=smm){
puts("-1");continue;
}
else{
solve_MX();
}
}
return ;
}
ZOJ3229 Shoot the Bullet [未AC]的更多相关文章
- ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)
题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...
- ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)
#pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...
- zoj3229 Shoot the Bullet(有源汇有上下界的最大流)
题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...
- ZOJ3229 Shoot the Bullet
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20756 思路:就讲一下有源汇上下界最大流的做法吧!对于所有的边,就按照无源汇 ...
- zoj3229 Shoot the Bullet (有源汇最大流)
题目大意:文文要给幻想乡的女♂孩子们拍照,一共n天,m个女♂孩子,每天文文至多拍D[i]张照片,每个女♂孩子总共要被文文至少拍G[i]次.在第i天,文文可以拍c[i]个女♂孩子,c[i]个女♂孩子中每 ...
- zoj 3229 Shoot the Bullet(无源汇上下界最大流)
题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...
- 九度OJ 1016 火星A + B 未AC版,整型存储不下
#include <iostream> #include <string.h> #include <sstream> #include <math.h> ...
- ZOJ 3229 Shoot the Bullet [上下界最大流]
ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...
- Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流
/** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...
随机推荐
- 【IdentityServer4文档】- 支持协议
IdentityServer 实现了以下协议: OpenID Connect OpenID Connect Core 1.0 (spec) OpenID Connect Discovery 1.0 ( ...
- Response.End方法
文章:在try...catch语句中执行Response.End()后如何停止执行catch语句中的内容 调用Response.End()方法能保证,只输出End方法之前的内容. 调用Context. ...
- LintCode-71.二叉树的锯齿形层次遍历
二叉树的锯齿形层次遍历 给出一棵二叉树,返回其节点值的锯齿形层次遍历(先从左往右,下一层再从右往左,层与层之间交替进行) 样例 给出一棵二叉树 {3,9,20,#,#,15,7}, 返回其锯齿形的层次 ...
- Windows SDK 非模态对话框的消息处理
在SDK中使用非模态对话框时的几个问题: 1.为什么要调用IsDialogMessage?? 2.非模态对话框与主窗口有什么区别? 3.如果不调用IsDialogMessage,消息能不能传递到对话框 ...
- asp.net中Repeater结合js实现checkbox的全选/全不选
前台界面代码: <input name="CheckAll" type="checkbox" id="CheckAll" value= ...
- Android出现:Your project path contains non-ASCII characters.
导入Project的出现: Error:(1, 0) Your project path contains non-ASCII characters. This will most likely ca ...
- hdu 2151 Worm (DP)
Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- [BZOJ4589]Hard Nim
description BZOJ 题意:\(n\)堆式子,每堆石子数量为\(\le m\)的质数,对于每一个局面玩\(Nim\)游戏,求后手必胜的方案数. data range \[n\le 10^9 ...
- [洛谷P4174][NOI2006]最大获利
题目大意:同Petya and Graph,数据范围改成$n\leqslant5\times10^3,m\leqslant5\times10^4$ 题解:同上 卡点:无 C++ Code: #incl ...
- [洛谷P3975][TJOI2015]弦论
题目大意:求一个字符串的第$k$大字串,$t$表示长得一样位置不同的字串是否算多个 题解:$SAM$,先求出每个位置可以到达多少个字串($Right$数组),然后在转移图上$DP$,若$t=1$,初始 ...