1070: [SCOI2007]修车 - BZOJ
Description
同一时刻有N位车主带着他们的爱车来到了汽车维修中心。维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的。现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待的时间最小。 说明:顾客的等待时间是指从他把车送至维修中心到维修完毕所用的时间。
Input
第一行有两个m,n,表示技术人员数与顾客数。 接下来n行,每行m个整数。第i+1行第j个数表示第j位技术人员维修第i辆车需要用的时间T。
Output
最小平均等待时间,答案精确到小数点后2位。
Sample Input
2 2
3 2
1 4
Sample Output
1.50
HINT
数据范围: (2<=M<=9,1<=N<=60), (1<=T<=1000)
费用流建图,把m个人每个人拆成n个点,表示的是第m个人倒数第i个修这个车,那么费用就是i*时间
没想到zkw费用流模板打错了
在dfs过程里
我是这么写的
function dfs(x,flow:longint):longint;
var
i,d,min:longint;
begin
flag[x]:=time;
if x=t then
begin
inc(ans,flow*dis[t]);
exit(flow);
end;
i:=first[x];
dfs:=;
while i<> do
begin
d:=dis[x]+w[i]-dis[last[i]];
min:=flow;
if min>liu[i] then min:=liu[i];
if (liu[i]>) and (d<f[last[i]]) then f[last[i]]:=d;
if (d=) and (flag[last[i]]<>time) and (min>) then
begin
d:=dfs(last[i],min);
dec(flow,d);
inc(dfs,d);
inc(liu[i xor ],d);
dec(liu[i],d);
end;
if flow= then break;
i:=next[i];
end;
end;
但是应该这么写
function dfs(x,flow:longint):longint;
var
i,d,min:longint;
begin
if x=t then
begin
inc(ans,flow*dis[t]);
exit(flow);
end;
i:=first[x];
flag[x]:=time;
dfs:=;
while i<> do
begin
d:=dis[x]+w[i]-dis[last[i]];
min:=flow;
if min>liu[i] then min:=liu[i];
if (liu[i]>) and (d<f[last[i]]) then f[last[i]]:=d;
if (d=) and (flag[last[i]]<>time) and (min>) then
begin
d:=dfs(last[i],min);
dec(flow,d);
inc(dfs,d);
inc(liu[i xor ],d);
dec(liu[i],d);
end;
if flow= then break;
i:=next[i];
end;
end;
应该先判断是否走到了汇点,再做标记,如果不这样的话,就无法多路增广了,即只能到达汇点一次,然后他会立即增加dis,这个时候dis就是错的了(因为较小的那个dis还没有增广完全)
对于其他的点,都是增广到不能再增广,所以没有问题,只要访问一次就行了(应该是这样的吧)
写了几遍了,连这个都没有发现,唉~~~~
const
maxn=;
maxm=;
inf=;
var
n,m,tot,s,t,ans,time:longint;
first,f,dis,flag:array[..maxn*maxm]of longint;
last,next,w,liu:array[..maxn*maxn*maxm*maxm]of longint; procedure insert(x,y,f,ww:longint);
begin
inc(tot);
last[tot]:=y;
next[tot]:=first[x];
first[x]:=tot;
w[tot]:=ww;
liu[tot]:=f;
end; procedure init;
var
i,j,k,x:longint;
begin
read(m,n);
tot:=;
s:=;
t:=n*m+n+;
for i:= to n do
for j:= to m do
begin
read(x);
for k:= to n do
begin
insert((j-)*n+k,n*m+i,,x*k);
insert(n*m+i,(j-)*n+k,,-x*k);
end;
end;
for i:= to n*m do
begin
insert(s,i,,);
insert(i,s,,);
end;
for i:= to n do
begin
insert(n*m+i,t,,);
insert(t,n*m+i,,);
end;
end; function dfs(x,flow:longint):longint;
var
i,d,min:longint;
begin
if x=t then
begin
inc(ans,flow*dis[t]);
exit(flow);
end;
i:=first[x];
flag[x]:=time;
dfs:=;
while i<> do
begin
d:=dis[x]+w[i]-dis[last[i]];
min:=flow;
if min>liu[i] then min:=liu[i];
if (liu[i]>) and (d<f[last[i]]) then f[last[i]]:=d;
if (d=) and (flag[last[i]]<>time) and (min>) then
begin
d:=dfs(last[i],min);
dec(flow,d);
inc(dfs,d);
inc(liu[i xor ],d);
dec(liu[i],d);
end;
if flow= then break;
i:=next[i];
end;
end; procedure work;
var
del,i:longint;
begin
while true do
begin
for i:=s to t do
f[i]:=inf;
inc(time);
dfs(s,inf);
del:=inf;
for i:=s to t do
if (flag[i]<>time) and (f[i]<del) then del:=f[i];
if del=inf then break;
for i:=s to t do
if flag[i]<>time then inc(dis[i],del);
end;
writeln(ans/n::);
end; begin
init;
work;
end.
1070: [SCOI2007]修车 - BZOJ的更多相关文章
- BZOJ 1070: [SCOI2007]修车 [最小费用最大流]
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4936 Solved: 2032[Submit][Status] ...
- 【BZOJ】1070: [SCOI2007]修车
1070: [SCOI2007]修车 Description 同 一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需 ...
- bzoj 1070: [SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2785 Solved: 1110[Submit][Status] ...
- bzoj 1070 [SCOI2007]修车(最小费用最大流)
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3515 Solved: 1411[Submit][Status] ...
- 1070: [SCOI2007]修车
1070: [SCOI2007]修车 https://www.lydsy.com/JudgeOnline/problem.php?id=1070 分析: 每个第几次修车等的时间都不一样,当前第i个人修 ...
- [BZOJ 1070] [SCOI2007] 修车 【费用流】
题目链接:BZOJ - 1070 题目分析 首先想到拆点,把每个技术人员拆成 n 个点,从某个技术人员拆出的第 i 个点,向某辆车连边,表示这是这个技术人员修的倒数第 i 辆车.那么这一次修车对整个答 ...
- 【BZOJ】1070: [SCOI2007]修车(费用流+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1070 好神的题!!!orz 首先我是sb不会拆点..... 首先,每一个技术人员维修车辆都有一个先后 ...
- BZOJ 1070: [SCOI2007]修车(费用流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1070 题意: 思路: 神奇的构图. 因为排在后面的人需要等待前面的车修好,这里将每个技术人员拆成n个 ...
- bzoj 1070 [SCOI2007]修车——网络流(拆边)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...
随机推荐
- Zend studio 12.5.1安装aptana
aptana是zend studio的一个插件.解决zend对于前台html支持,加亮的问题. 安装方法其实很简单 ,直接给出aptana的地址了. http://download.aptana.co ...
- Javascript Class
做个记录,javascript 如何创建类? 有早期的,有原型的,有构造函数的 // early javascript object var o = {}; o.color = 'red'; o.sh ...
- (转)Yale CAS + .net Client 实现 SSO(2)
第一部分:安装配置 Tomcat 第二部分:安装配置 CAS 1. 下载 CAS 及.NET CAS client. CAS下载地址:http://www.jasig.org/cas/download ...
- Facebook抛弃了HTML5,微信却捧火了它
苹果普及了HTML5技术,Facebook押注HTML5上,却受到不小的打击,导致在后来一段时间里,唱衰HTML5的言论成为媒体的一种幸灾乐祸的态度,人人避而不谈.微信通过公众号的形式,以游戏.营销重 ...
- 一个线程间的通讯小程序__(Java_Thread_Inout.Output)
//多线程通讯 //多个线程处理同一资源,但是任务不同 //等待唤醒方法: //wait():将线程变成为冻结状态,线程会被存储在线程池中; //notify():唤醒线程中的一个线程(任意的) // ...
- js设计模式(9)---代理模式
0.前言 KG.PP被交易到了布鲁克林篮网,我的心情很复杂,一方面为他们不能终老celtics感到惋惜,另一方面为他们能够再次冲击总冠军感到高兴.从07年以来,作为一个铁杆celtics球迷,他们给我 ...
- 错误解决mysql - Event Scheduler: No data - zero rows fetched, selected, or processed
当遇到一个NOT FOUND(无数据)的警告时,使用一个包含清除警告语句的条件句柄处理,就可以继续处理程序并退出句柄. 这个问题在MySQL5.6.3之后的版本已经解决了,所以该解决方法不是必要的. ...
- [DevExpress]ChartControl之时间轴示例
关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; name ...
- php intval()函数
格式:int intval(mixed $var [, int $base]); 1.intval()的返回值是整型,1或者0.可作用于数组或者对象(对象报错信息:Notice: Object of ...
- linux终端io笔记
简介 终端的两种工作模式:以行为单位的工作模式,以字符数或时间为单位自定义模式 终端判断函数: int isatty(int fd) 终端属性的获取与设置: int tcgetattr(int fd, ...