【解题思路】

  考虑拆点,得到一个二分图:左边点<i,j>表示第i个技师按顺序第j辆修的车,右边点k表示第k个车主,连接左右的边表示第k个车主可能成为第i个技师的第j个客户。

  因为是二分图,所以直接跑KM即可,复杂度O(n3m);或者考虑费用流,左图都和源点连边,右图都和汇点连边,容费均为1,跑个流即可,复杂度O(松)。

【参考代码】

  费用流实现:

 #pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#define REP(i,low,high) for(register int i=(low);i<=(high);i++)
#define INF 0x7f7f7f7f
using namespace std;
template<typename T> inline bool getmin(T &tar,const T &pat) {return pat<tar?tar=pat,:;}
const static int T=; static int E=; bool inq[T+]; int w,c,hed[T+],pre[T+],que[T<<]; long long dst[T+],tim[][];
struct edge
{
int fr,to,fl,nx; long long vl;
edge() {fl=INF;}
edge(const int &x,const int &y,const int &f,const long long &v) {fr=x,to=y,fl=f,vl=v,nx=hed[x],hed[x]=E;}
}edg[];
inline void add_edge(const int &fr,const int &to,const int &fl,const long long &vl) {edg[++E]=edge(fr,to,fl,vl),edg[++E]=edge(to,fr,,-vl);}
inline bool SPFA()
{
memset(dst,0x7f,sizeof dst),dst[]=que[]=0ll,memset(inq,,sizeof inq),inq[]=;
for(int head=-,tail=;head++<tail;)
{
int now=que[head];
for(int i=hed[now];i;i=edg[i].nx)
{
int p=edg[i].to; if(edg[i].fl&&getmin(dst[p],dst[now]+edg[i].vl)) {pre[p]=i; if(!inq[p]) inq[que[++tail]=p]=;}
}
inq[now]=;
}
return dst[T]<INF;
}
int main()
{
scanf("%d%d",&w,&c),memset(hed,,sizeof hed); REP(i,,c) REP(j,,w) scanf("%lld",&tim[j][i]); int n=w*c; long long ans=0ll;
REP(i,,n) add_edge(,i,,0ll); REP(i,,c) add_edge(n+i,T,,0ll); REP(i,,w) REP(j,,c) REP(k,,c) add_edge((i-)*c+j,n+k,,tim[i][k]*j);
while(SPFA())
{
int mnr=INF; for(int i=pre[T];i;i=pre[edg[i].fr]) getmin(mnr,edg[i].fl);
for(int i=pre[T];i;i=pre[edg[i].fr]) edg[i].fl-=mnr,edg[i^].fl+=mnr,ans+=edg[i].vl*mnr;
}
return printf("%.2lf\n",(double)ans/c),;
}

bzoj1070题解的更多相关文章

  1. LG2053/BZOJ1070 「SCOI2007」修车 费用流

    问题描述 LG2053 BZOJ1070 题解 将\(m\)个修理工拆为\(n \times m\)个,将修理工和车辆看做二分图,连出一个完全二分图. 边流量为\(1\),费用为时间,费用流即可. \ ...

  2. BZOJ1070:[SCOI2007]修车——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1070 https://www.luogu.org/problemnew/show/P2053#sub ...

  3. 【BZOJ1070】[SCOI2007]修车

    [BZOJ1070][SCOI2007]修车 题面 以后要多写题面flag 题目描述 同一时刻有\(N\)位车主带着他们的爱车来到了汽车维修中心.维修中心共有\(M\)位技术人员,不同的技术人员对不同 ...

  4. 【BZOJ1070】[SCOI2007]修车 费用流

    [BZOJ1070][SCOI2007]修车 Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. ...

  5. [bzoj1070][SCOI2007]修车_费用流

    修车 bzoj-1070 SCOI-2007 题目大意:有m个人要修n台车,每个工人修不同的车的时间不同,问将所有的车都修完,最少需要花费的时间. 注释:$2\le m\le 9$,$1\le n \ ...

  6. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  7. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  8. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  9. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

随机推荐

  1. git安装和使用方法url

    1.如何在ubuntu下使用Github? https://blog.csdn.net/tina_ttl/article/details/51326684 https://segmentfault.c ...

  2. 38th 字符串与 列表间的转换

    字符串与 列表间的转换 如何利用字符串 'Life is short ,I use python'输出 :'python use I, short is Life' s = 'Life is shor ...

  3. 36.两个链表的第一个公共结点(python)

    题目描述 输入两个链表,找出它们的第一个公共结点. class Solution: def FindFirstCommonNode(self, pHead1, pHead2): # write cod ...

  4. Vulhub-漏洞环境的搭建

    安装Docker #安装pip curl -s https://bootstrap.pypa.io/get-pip.py | python3 #安装最新版docker curl -s https:// ...

  5. 用记事本和Eclipse编写Java程序

    JRE(Java Runtime Environment    Java运行环境) 包括Java虚拟机(JVM Java Virtual Machine)和Java程序所需的核心类库等,如果想要运行一 ...

  6. SQL 查询子句

    SQL WHERE Clause(查询子句) WHERE 子句用于过滤记录. SQL WHERE 子句 WHERE子句用于提取满足指定标准的记录. SQL WHERE 语法 SELECT column ...

  7. Flex布局(一)

    Flex Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为Flex布局.display: flex;, 行内元 ...

  8. firefox显示 您的连接不安全 解决办法

    在地址栏键入"about:config" 点击“我了解此风险” 在下方任意位置右键,选择新建布尔值 输入首选项名称为“security.enterprise_roots.enabl ...

  9. (转)openfire插件开发(一)

    转:http://blog.csdn.net/lovexieyuan520/article/details/37774909 1. 在上一篇博文中,我介绍了Openfire3.9.3源代码导入ecli ...

  10. Win7下使用DbgPrint

    在Win7下默认DbgPrint输出信息后,使用DbgView看不到内容. 新建一个reg文件,双击导出就行了. Windows Registry Editor Version 5.00 [HKEY_ ...