[SCOI 2007] 修车
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=1070
[算法]
首先 , 我们发现 , 在倒数第i个修车会对答案产生i * k的贡献
将每辆车建一个点 , 每名技术人员建n个点 ,将车与技术人员连边 , 第i个技术人员的第j个点与第k辆车连边表示k是i修的倒数第j辆车
然后在这张图上求最小费用最大流 , 即可
时间复杂度 : O(Costflow(NM , N ^ 2M))
[代码]
#include<bits/stdc++.h>
using namespace std;
#define MAXN 550
const int INF = 1e9; struct edge
{
int to , w , cost , nxt;
} e[MAXN * MAXN * ]; int n , m , tot , ans , S , T;
int a[MAXN][MAXN];
int head[MAXN * MAXN] , dist[MAXN * MAXN] , pre[MAXN * MAXN] , incf[MAXN * MAXN];
bool inq[MAXN * MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void addedge(int u , int v , int w , int cost)
{
++tot;
e[tot] = (edge){v , w , cost , head[u]};
head[u] = tot;
++tot;
e[tot] = (edge){u , , -cost , head[v]};
head[v] = tot;
}
inline bool spfa()
{
int l , r;
static int q[MAXN * MAXN];
for (int i = ; i <= T; i++)
{
pre[i] = ;
dist[i] = INF;
incf[i] = INF;
inq[i] = false;
}
q[l = r = ] = S;
dist[S] = ;
inq[S] = true;
while (l <= r)
{
int cur = q[l++];
inq[cur] = false;
for (int i = head[cur]; i; i = e[i].nxt)
{
int v = e[i].to , w = e[i].w , cost = e[i].cost;
if (w > && dist[cur] + cost < dist[v])
{
dist[v] = dist[cur] + cost;
incf[v] = min(incf[cur] , w);
pre[v] = i;
if (!inq[v])
{
q[++r] = v;
inq[v] = true;
}
}
}
}
if (dist[T] != INF) return true;
else return false;
}
inline void update()
{
int now = T , pos;
while (now != S)
{
pos = pre[now];
e[pos].w -= incf[T];
e[pos ^ ].w += incf[T];
now = e[pos ^ ].to;
}
ans += dist[T] * incf[T];
} int main()
{ read(m); read(n);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
read(a[i][j]);
}
}
tot = ;
S = n * m + n + , T = S + ;
for (int i = ; i <= n; i++) addedge(S , i , , );
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
for (int k = ; k <= n; k++)
{
addedge(i , n + (j - ) * n + k , , a[i][j] * k);
}
}
}
for (int i = ; i <= n * m; i++) addedge(i + n , T , , );
while (spfa()) update();
printf("%.2lf\n" , 1.0 * ans / n); return ; }
[SCOI 2007] 修车的更多相关文章
- 图论(网络流):SCOI 2007 修车
同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待的时间最小 ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- 解题:SCOI 2007 蜥蜴
题面 拆点跑最大流 所有能跑出去的点连向汇点,容量为inf 原点连向所有初始有蜥蜴的点,容量为1 每根柱子拆成两个点“入口”和“出口”,入口向出口连容量为高度的边,出口向别的有高度的柱子的入口连容量为 ...
- 【SCOI 2007】 降雨量
[题目链接] 点击打开链接 [算法] 线段树 此题细节很多,写程序时要细心! [代码] #include<bits/stdc++.h> using namespace std; #defi ...
- [ SCOI 2007 ] Perm
\(\\\) \(Description\) 给出只包括多个\(0\text~ 9\)的数字集,求有多少个本质不同的全排列,使得组成的数字能够整除\(M\). \(|S|\in [1,10]\),\( ...
- [SCOI 2007] 排列
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1072 [算法] 状压DP [代码] #include<bits/stdc++. ...
- @loj - 2674@ 「NOI2012」美食节
目录 @description@ @solution@ @accepted code@ @details@ @description@ CZ 市为了欢迎全国各地的同学,特地举办了一场盛大的美食节. 作 ...
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
/** * 版权所有(C) 2016 * @author www.xiongge.club * @date 2016-12-7 上午10:03:29 */ package xlsx; /** * @C ...
- BZOJ 2007: [Noi2010]海拔
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2410 Solved: 1142[Submit][Status] ...
随机推荐
- 什么是Kubernetes?
刚刚进学校实验室,第一次开会导师和小组同学说了n次Kubernetes,从来没听过,一脸懵逼. Kubernetes也有很多人把它叫K8S, 原文链接:http://omerio.com/2015/1 ...
- hdu 1421经典dp
#include<stdio.h> #include<stdlib.h> #define N 2001 #define inf 0x3fffffff int a[N],dp[N ...
- 没有上司的舞会(hdu 1520)
题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会 ...
- [NOIP2003] 普及组
乒乓球 模拟 /*By SilverN*/ #include<iostream> #include<algorithm> #include<cstring> #in ...
- markdown八条基础语法
1.空行 答:使用全角打出空格,之后再换行就可以打出空行了 2.标题 答:#表示标题,#表示一级标题,字号最大,一共有六级标题 3.列表 答:- 无序列表,1. 有序列表,注意和文本之间有空格 4.链 ...
- Palindrome Partitioning (回文子串题)
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 洛谷 P1731 [NOI1999]生日蛋糕
P1731 [NOI1999]生日蛋糕 题目背景 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层 生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M ...
- npm Error: Cannot find module 'proto-list'
Error: Cannot find module 'proto-list' at Function.Module._resolveFilename (module.js:338:15) at Fun ...
- QT窗体间传值总结之Signal&Slot
在写程序时,难免会碰到多窗体之间进行传值的问题.依照自己的理解,我把多窗体传值的可以使用的方法归纳如下: 1.使用QT中的Signal&Slot机制进行传值: 2.使用全局变量: 3.使用pu ...
- 运维平台之CMDB系统建设
CMDB是运维的基础核心系统,所有的元数据和共享数据管理源,类似于业务中的账号平台的作用.本篇文章,我将从概念篇.模型篇.到实现与实施篇具体的进行阐述. CMDB也称配置管理,配置管理一直被认为是 I ...