BZOJ 1070: [SCOI2007]修车(费用流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1070
题意:

思路:
神奇的构图。
因为排在后面的人需要等待前面的车修好,这里将每个技术人员拆成n个点,第k个点表示该技术人员倒数第k的顺序来修理该车,此时它的时间对于答案的贡献就是kw。
最后跑一遍最小费用流。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; int n,m; struct Edge
{
int from, to, cap, flow, cost;
Edge(int u, int v, int c, int f, int w) :from(u), to(v), cap(c), flow(f), cost(w) {}
}; struct MCMF
{
int n, m;
vector<Edge> edges;
vector<int> G[maxn];
int inq[maxn];
int d[maxn];
int p[maxn];
int a[maxn]; void init(int n)
{
this->n = n;
for (int i = ; i<n; i++) G[i].clear();
edges.clear();
} void AddEdge(int from, int to, int cap, int cost)
{
edges.push_back(Edge(from, to, cap, , cost));
edges.push_back(Edge(to, from, , , -cost));
m = edges.size();
G[from].push_back(m - );
G[to].push_back(m - );
} bool BellmanFord(int s, int t, int &flow, int & cost)
{
for (int i = ; i<n; i++) d[i] = INF;
memset(inq, , sizeof(inq));
d[s] = ; inq[s] = ; p[s] = ; a[s] = INF; queue<int> Q;
Q.push(s);
while (!Q.empty()){
int u = Q.front(); Q.pop();
inq[u] = ;
for (int i = ; i<G[u].size(); i++){
Edge& e = edges[G[u][i]];
if (e.cap>e.flow && d[e.to]>d[u] + e.cost){
d[e.to] = d[u] + e.cost;
p[e.to] = G[u][i];
a[e.to] = min(a[u], e.cap - e.flow);
if (!inq[e.to]) { Q.push(e.to); inq[e.to] = ; }
}
}
} if (d[t] == INF) return false;
flow += a[t];
cost += d[t] * a[t];
for (int u = t; u != s; u = edges[p[u]].from)
{
edges[p[u]].flow += a[t];
edges[p[u] ^ ].flow -= a[t];
}
return true;
} int MincostMaxdflow(int s, int t){
int flow = , cost = ;
while (BellmanFord(s, t, flow, cost));
return cost;
}
}t; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&m,&n))
{
int src=,dst=n*m+n+;
t.init(dst+);
for(int i=;i<=n;i++)
{
t.AddEdge(src,i,,);
for(int j=;j<=m;j++)
{
int x; scanf("%d",&x);
for(int k=;k<=n;k++)
t.AddEdge(i,j*n+k,,k*x);
}
}
for(int j=n+;j<=m*n+n;j++)
t.AddEdge(j,dst,,);
int ans = t.MincostMaxdflow(src,dst);
printf("%.2f\n",(double)ans/n);
}
return ;
}
BZOJ 1070: [SCOI2007]修车(费用流)的更多相关文章
- bzoj 1070: [SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2785 Solved: 1110[Submit][Status] ...
- BZOJ.1070.[SCOI2007]修车(费用流SPFA)
题目链接 /* 神tm看错题*2.. 假如人员i依次维修W1,W2,...,Wn,那么花费的时间是 W1 + W1+W2 + W1+W2+W3... = W1*n + W2*(n-1) + ... + ...
- BZOJ 1070: [SCOI2007]修车 [最小费用最大流]
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4936 Solved: 2032[Submit][Status] ...
- bzoj 1070 [SCOI2007]修车(最小费用最大流)
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3515 Solved: 1411[Submit][Status] ...
- [BZOJ1070][SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 6209 Solved: 2641[Submit][Status] ...
- BZOJ 1070 拆点 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 5860 Solved: 2487[Submit][Status] ...
- [BZOJ 1070] [SCOI2007] 修车 【费用流】
题目链接:BZOJ - 1070 题目分析 首先想到拆点,把每个技术人员拆成 n 个点,从某个技术人员拆出的第 i 个点,向某辆车连边,表示这是这个技术人员修的倒数第 i 辆车.那么这一次修车对整个答 ...
- 【BZOJ 1070】[SCOI2007]修车 费用流
就是拆个点限制一下(两点一排一大片),这道题让我注意到了限制这个重要的词.我们跑网络流跑出来的图都是有一定意义的,一般这个意义就对应了问题的一种方案,一般情况下跑一个不知道对不对的方案是相对容易的我们 ...
- 【BZOJ1070】[SCOI2007]修车 费用流
[BZOJ1070][SCOI2007]修车 Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. ...
- bzoj 1070 [SCOI2007]修车——网络流(拆边)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...
随机推荐
- 深入剖析Kubernetes k8s
深入剖析Kubernetes k8s 毫无疑问,Kubernetes 已经成为容器领域当之无愧的事实标准.除了 Google.Microsoft 等技术巨擘们在容器领域里多年的博弈外,国内的 BAT. ...
- Javascript原生之用cssText批量修改样式
一般情况下我们用js设置元素对象的样式会使用这样的形式: var element= document.getElementById(“id”);element.style.width=”20px”;e ...
- html 基本布局介绍
1.div默认是纵向排列的,例子如下: <div id="wrap"> <div id="div1">div1</div> ...
- ubunta apt install error
ubuntu系统: 用apt-get命令安装一些软件包时,总报错:E:could not get lock /var/lib/dpkg/lock -open等 出现这个问题的原因可能是有另外一个程序正 ...
- lnmp重置密码
wget http://soft.vpser.NET/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_password.sh
- ELK学习笔记之F5 DNS可视化让DNS运维更安全更高效-F5 ELK可视化方案系列(3)
0x00 概述 此文力求比较详细的解释DNS可视化所能带来的场景意义,无论是运维.还是DNS安全.建议仔细看完下图之后的大篇文字段落,希望能引发您的一些思考. 在“F5利用Elastic stack( ...
- Leetcode480-Sliding Window Median
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- P1297 [国家集训队]单选错位(期望)
P1297 [国家集训队]单选错位 期望入门 我们考虑涂到第$i$道题时的情况 此时题$i$答案有$a[i]$种,我们可能涂$a[i+1]$种 分类讨论: 1.$a[i]>=a[i+1]$: 可 ...
- 如何用git将项目代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- 缩点:Power Plant;
题目传送门:[UVALive 6437]Power Plant 题目大意:T组数据,给定一幅带权图(n, m), 然后给定k个点, 与图中存在有若干条边.每个点都要至少要和这k个点的一个点直接或间接相 ...