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 ...
随机推荐
- TCP协议中的三次握手和四次挥手(图解)(转)
转自:http://blog.csdn.net/whuslei/article/details/6667471 建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看 ...
- 【LeetCode】BFS || DFS [2017.04.10--2017.04.17]
[102] Binary Tree Level Order Traversal [Medium-Easy] [107] Binary Tree Level Order Traversal II [Me ...
- 数据库常用SQL语句
显示所有的数据库 show databases; 新建数据库 create database if not exists 数据库名 default character set = 'utf8'; 删 ...
- Nginx---文档(从入门到精通)
very good http://tengine.taobao.org/book/index.html
- 概率——17icpc西安
不知道为什么是这样子的.. #include<bits/stdc++.h> using namespace std; int m,n; int main(){ while(scanf(&q ...
- 攻防世界 MISC篇
Excaliflag 一张图片,winhex打开没什么发现,分值不高,应该属于常见的图片隐写题目.如果对于图片的格式有详细的了解,应该很容易就能够知道了属于最低有效位(LSB)隐写,下面是通过phot ...
- 18、webservice使用
1.将axis2.war文件拷到tomcat,webapp文件夹下,然后重启tomcat 访问
- hbase之setCaching 和 setBatch 和setMaxResultSize
scan的setBatch()用法 val conf = HBaseConfiguration.create() val table: Table = ConnectionFactory.create ...
- Codeforces 1169A Circle Metro
题目链接:codeforces.com/contest/1169/problem/A 题意:有俩个地铁,一个从 1 → 2 → …→ n → 1→ 2 →…, 一个 从 n → n-1 →…→ 1 → ...
- mkdir和_mkdir的区别
没有下划线的位不符合ISO c++ 标准的写法,标准要求带下划线的标准,没有下划线的是为了兼容以前的版本.