bzoj 3280: 小R的烦恼 (网络流)
和开发计划一样(数组开太小wa了好多次,然后为什么这么慢?
type
arr=record
toward,next,cap,cost:longint;
end;
const
maxm=;
maxn=;
var
edge:array[..maxm]of arr;
dist,first,sch,a,new,old,p,slack:array[..maxn]of longint;
chose:array[..maxn]of boolean;
maxcost,maxflow,n,s,t,tot,esum,i,tt,sum,jj:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(i,j,k,l:longint);
begin
inc(esum);
edge[esum].toward:=j;
edge[esum].next:=first[i];
first[i]:=esum;
edge[esum].cap:=k;
edge[esum].cost:=l;
end; procedure addedge(i,j,k,l:longint);
begin
add(i,j,k,l);
add(j,i,,-l);
end; procedure into;
var
n,m1,m2,i,j,k,cost1,time:longint;
begin
readln(n,m1,m2);
fillchar(first,sizeof(first),);
esum:=-;
for i:= to m1 do sch[i]:=i;
tot:=m1;
for i:= to n do begin
inc(tot);
new[i]:=tot;
inc(tot);
old[i]:=tot;
end;
inc(tot);
s:=tot;
inc(tot);
t:=tot;
for i:= to n do begin
read(a[i]);
inc(sum,a[i]);
end;
for i:= to m1 do begin
read(j,p[i]);
addedge(s,sch[i],j,);
end;
for i:= to n do begin
addedge(s,old[i],a[i],);
for j:= to m1 do
addedge(sch[j],new[i],a[i],p[j]);
addedge(new[i],t,a[i],);
end;
for i:= to m2 do begin
read(time,cost1);
for j:= to n-time do
for k:=j+time+ to n do
addedge(old[j],new[k],maxlongint,cost1);
end;
end; function aug(x,flow:longint):longint;
var
now,more,i,too,value:longint;
begin
if x=t then begin
inc(maxflow,flow);
inc(maxcost,dist[s]*flow);
exit(flow);
end;
// writeln(x);
i:=first[x];
chose[x]:=true;
now:=;
while i>= do begin
too:=edge[i].toward;
value:=edge[i].cost;
if (edge[i].cap>) and (not chose[too]) then
if dist[x]=dist[too]+value then begin
more:=aug(too,min(edge[i].cap,flow-now));
dec(edge[i].cap,more);
inc(edge[i xor ].cap,more);
inc(now,more);
if flow=now then exit(flow);
end
else
slack[too]:=min(slack[too],dist[too]+value-dist[x]);
i:=edge[i].next;
end;
exit(now);
end; function rel:boolean;
var
i,spent:longint;
begin
spent:=maxlongint;
for i:= to tot do
if not chose[i] then spent:=min(spent,slack[i]);
if spent=maxlongint then exit(false);
for i:= to tot do
if chose[i] then inc(dist[i],spent);
exit(true);
end; begin
readln(tt);
for jj:= to tt do begin
sum:=;
into;
fillchar(dist,sizeof(dist),);
maxcost:=;
maxflow:=;
repeat
for i:= to tot do slack[i]:=maxlongint;
repeat
fillchar(chose,sizeof(chose),false);
until aug(s,maxlongint)<=;
until not rel;
write('Case ',jj,': ');
if sum=maxflow then writeln(maxcost)
else writeln('impossible');
end;
end.
bzoj 3280: 小R的烦恼 (网络流)的更多相关文章
- BZOJ 3280: 小R的烦恼 & BZOJ 1221: [HNOI2001] 软件开发
3280: 小R的烦恼 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 399 Solved: 200[Submit][Status][Discuss ...
- bzoj 3280: 小R的烦恼 费用流
题目: Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要求小R帮助他一起解决一个难题. 问题是这样的,程设老师最近要进行一项 ...
- BZOJ 3280: 小R的烦恼
Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要 求小R帮助他一起解决一个难题.问题是这样的,程设老师最近要进行一项邪恶的实 ...
- 【BZOJ】【3280】小R的烦恼
网络流/费用流 和软件开发那题基本相同,只是多加了一个“雇佣研究生”的限制:不同价格的研究生有不同的数量…… 那么只需加一个附加源点,对每一种研究生连边 S->ss 容量为l[i],费用为p[i ...
- BZOJ3280: 小R的烦恼
题解: 随便建一下图费用流就可以过吧... 代码: #include<cstdio> #include<cstdlib> #include<cmath> #incl ...
- 【BZOJ3280】小R的烦恼 最小费用最大流
[BZOJ3280]小R的烦恼 Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要求小R帮助他一起解决一个难题. 问题是这样的 ...
- BZOJ_3280_小R的烦恼_最小费用最大流
BZOJ_3280_小R的烦恼_最小费用最大流 Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要 求小R帮助他一起解决一个难 ...
- bzoj3280: 小R的烦恼(最小费用最大流)
Description 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要 求小R帮助他一起解决一个难题.问题是这样的,程设老师最近要进行一项邪恶的实 ...
- 【bzoj3280】小R的烦恼 费用流
题目描述 小R最近遇上了大麻烦,他的程序设计挂科了.于是他只好找程设老师求情.善良的程设老师答应不挂他,但是要求小R帮助他一起解决一个难题. 问题是这样的,程设老师最近要进行一项邪恶的实验来证明P=N ...
随机推荐
- CLR via c#读书笔记八:泛型
1.定义泛型类型或方法时,为类型指定的任何变量(比如T)都称为类型参数.使用泛型类型或方法时指定的具体数据类型称为类型实参. 2.System.Collections.Concurrent命名空间提供 ...
- 14、Java并发编程:CountDownLatch、CyclicBarrier和Semaphore
Java并发编程:CountDownLatch.CyclicBarrier和Semaphore 在java 1.5中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如CountDownLatch ...
- 初学Direct X(8) ——碰撞检测
初学Direct X(8) --碰撞检测 真正让一个游戏鹤立鸡群的是程序对碰撞的响应有多好,这里介绍两种检测的方法: 1) 基于边框的碰撞检测 2) 基于距离的碰撞检测 1. 基于边框的碰撞检测 1. ...
- 应用UserDefaults储存游戏分数和最高分
应用UserDefaults储存游戏分数和最高分 我们在GameScene.swift里 private var currentScore:SKLabelNode! // 当前分数节点 private ...
- 57[LeetCode] Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- Linux命令详解----ln
ln命令 ln命令为文件或文件夹创建连接,连接类型有硬链接和符号连接两种,符号连接需要使用"-s"选项 ln语法 ln [选项] 参数 使用 ln --help查看可用选项 [ro ...
- Java简单工厂模式
Java简单工厂模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述简单工厂模式的:简单工厂模式是类的创建模式,又叫做静态工厂方法(Static Factory Method)模式.简 ...
- SGU 194 Reactor Cooling(无源无汇上下界可行流)
Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...
- 一个项目的Makefile编写及调试
父Makefile 在src目录下包含很多文件夹,那么需要遍历所有的目录执行Makefile,那么给一个在src目录下的Makefile. # 需要排除的目录 exclude_dirs := incl ...
- C# Winform防止闪频和再次运行
其实想实现只允许运行一个实例很简单,就是从program的入口函数入手.有两种情况: 第一种,用户运行第二个的时候给一个提示: using System; using System.Collectio ...