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 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...
随机推荐
- 略谈Android之Intent
前言:大家都知道Android程序的实现一般都由四大组件构成: Activity :Android程序实现功能的主体,提供了和客户交互的界面,也提供了和后台交互的功能. Service :是一个没有界 ...
- HDU 5478 Can you find it(快速幂)
Problem Description Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109 ...
- x64、x86_64、x64三者的区别
x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为“IA ...
- 用LINQ在集合中查询特定对象
这里是原文出处: 简单的概括LINQ LINQ是Language-Integrated Query的缩写,是C# 3.0和VB 9.0中新加入的语言特性,可以在编程时使用内置的查询语言进行基于集合的操 ...
- iOS数据持久化(二)SQLite
一.什么是SQLite SQLite是一款轻型的嵌入式数据库,它占用资源非常的低,处理速度快,非常适合用于移动端开发. 二.使用 创建DataBaseHandle.h & DataB ...
- [javascript|基本概念|Object]学习笔记
对象:数据和功能的集合 创建对象:new 对象类型名称 e.g.: var o = new Object(); 或 var o = new Object(省略(),不推荐) 或 var o = {}( ...
- iOS开发笔记-两种单例模式的写法
iOS开发笔记-两种单例模式的写法 单例模式是开发中最常用的写法之一,iOS的单例模式有两种官方写法,如下: 不使用GCD #import "ServiceManager.h" ...
- HTML5-WebWorker
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Bundle、Intent、SharedPreferences
Intent与Bundle的共同点:都继承Parcelable Intent传值与Bundle传值的区别 eg:我现在要从A界面 跳转到B界面或者C界面 这样的话 我就需要写2个Intent ...
- Silverlight自动根据屏幕分辨率进行布局
xaml: <UserControl x:Class="SLCenterLayout.MainPage" xmlns="http://schemas.microso ...