bzoj1070题解
【解题思路】
考虑拆点,得到一个二分图:左边点<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题解的更多相关文章
- LG2053/BZOJ1070 「SCOI2007」修车 费用流
问题描述 LG2053 BZOJ1070 题解 将\(m\)个修理工拆为\(n \times m\)个,将修理工和车辆看做二分图,连出一个完全二分图. 边流量为\(1\),费用为时间,费用流即可. \ ...
- BZOJ1070:[SCOI2007]修车——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1070 https://www.luogu.org/problemnew/show/P2053#sub ...
- 【BZOJ1070】[SCOI2007]修车
[BZOJ1070][SCOI2007]修车 题面 以后要多写题面flag 题目描述 同一时刻有\(N\)位车主带着他们的爱车来到了汽车维修中心.维修中心共有\(M\)位技术人员,不同的技术人员对不同 ...
- 【BZOJ1070】[SCOI2007]修车 费用流
[BZOJ1070][SCOI2007]修车 Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. ...
- [bzoj1070][SCOI2007]修车_费用流
修车 bzoj-1070 SCOI-2007 题目大意:有m个人要修n台车,每个工人修不同的车的时间不同,问将所有的车都修完,最少需要花费的时间. 注释:$2\le m\le 9$,$1\le n \ ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
随机推荐
- loj2472[九省联考2018]IIIDX
题意:要求构造一个d的排列使得满足d[i/k]<=d[u]且字典序最大. 标程(bzoj上并不能过): #include<bits/stdc++.h> #define mid ((l ...
- Linux 临时和永久关闭 Selinux
查看当前 Selinux 状态:getenforce 临时关闭 Selinux:setenforce 0 永久关闭 Selinux: vim /etc/sysconfig/selinux 将 SELI ...
- The 'with' and 'as' Keywords
Programming is all about getting the computer to do the work. Is there a way to get Python to automa ...
- Scala(一)基础
OOP 面向对象编程 AOP 面向切面编程 FP 函数式编程 编程语言都要定义变量,一些代码是用来注释的,变量和变量之间有一些关系,要做一些运算,运算离不开流程控制,进行运算的数据往往来自数据结构,最 ...
- 数据结构(c语言版,严蔚敏)第1章绪论
第1章严蔚敏
- mongodb数据库管道操作
1.$project(修改文档的结构,可以用来重命名.增加或删除文档中的字段) db.order.aggregate([ { $project:{ rade_no:1, all_price:1} } ...
- IntelliJ IDEA创建Maven web项目速度慢的解决方法
在Properties中添加Name:archetypeCatalog和Value:internal,如下图那样
- Mysql LOAD DATA读取客户端任意文件漏洞复现(原理分析)
环境搭建 怎么设置Mysql支持外联? use mysql; grant all privileges on *.* to root@'%' identified by '密码'; //授权语句 fl ...
- Windows 驱动模型的发展历史
直接从win95/98说起,因为之前的系统基本上没有保护模式的概念,程序员可以直接修改任意内存的数据.在95/98中采用的内核开发模型是VxD(虚拟设备驱动),在dos时期,程序认为它们拥有系统的一切 ...
- CSS:CSS 文本格式
ylbtech-CSS:CSS 文本格式 1.返回顶部 1. CSS 文本格式 文本格式 This text is styled with some of the text formatting pr ...