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]修车(费用流)的更多相关文章

  1. bzoj 1070: [SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2785  Solved: 1110[Submit][Status] ...

  2. BZOJ.1070.[SCOI2007]修车(费用流SPFA)

    题目链接 /* 神tm看错题*2.. 假如人员i依次维修W1,W2,...,Wn,那么花费的时间是 W1 + W1+W2 + W1+W2+W3... = W1*n + W2*(n-1) + ... + ...

  3. BZOJ 1070: [SCOI2007]修车 [最小费用最大流]

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 4936  Solved: 2032[Submit][Status] ...

  4. bzoj 1070 [SCOI2007]修车(最小费用最大流)

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3515  Solved: 1411[Submit][Status] ...

  5. [BZOJ1070][SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 6209  Solved: 2641[Submit][Status] ...

  6. BZOJ 1070 拆点 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 5860  Solved: 2487[Submit][Status] ...

  7. [BZOJ 1070] [SCOI2007] 修车 【费用流】

    题目链接:BZOJ - 1070 题目分析 首先想到拆点,把每个技术人员拆成 n 个点,从某个技术人员拆出的第 i 个点,向某辆车连边,表示这是这个技术人员修的倒数第 i 辆车.那么这一次修车对整个答 ...

  8. 【BZOJ 1070】[SCOI2007]修车 费用流

    就是拆个点限制一下(两点一排一大片),这道题让我注意到了限制这个重要的词.我们跑网络流跑出来的图都是有一定意义的,一般这个意义就对应了问题的一种方案,一般情况下跑一个不知道对不对的方案是相对容易的我们 ...

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

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

  10. bzoj 1070 [SCOI2007]修车——网络流(拆边)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...

随机推荐

  1. NGINX的几个应用场景

    NGINX的几个应用场景 两个参考地址: NGINX的百度百科:https://baike.baidu.com/item/nginx/3817705?fr=aladdin NGINX的中文网站:htt ...

  2. Linux基础命令---切换用户su

    su 临时切换身份到另外一个用户,使用su切换用户之后,不会改变当前的工作目录,但是会改变一些环境变量. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUS ...

  3. 高性能NIO框架Netty-对象传输

    http://cxytiandi.com/blog/detail/17403 上篇文章高性能NIO框架Netty入门篇我们对Netty做了一个简单的介绍,并且写了一个入门的Demo,客户端往服务端发送 ...

  4. JustOj 2043: N!

    题目描述 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出,赛后我们会检查代码,如有发现,该位同学总分记0分处理) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把 ...

  5. Android开发常见错误汇总

    [错误信息] [2011-01-19 16:39:10 - ApiDemos] WARNING: Application does not specify an API level requireme ...

  6. MaxiSYS Elite

    The Maxisys Elite is Autel UK’s top of the range diagnostic and analysis scanner with advanced J2534 ...

  7. msyql -3m架构详解

    我们先来回顾一下mmm的概念,它是一套灵活的基于perl编写的脚本程序,自己本身不提供mysql服务的功能,它是用来对mysql replication 进行监控和故障迁移,并能管理mysql Mas ...

  8. LINUX部署SVN服务器

    1.安装SVN服务端 yum install -y subversion 2.创建svn版本库 mkdir -p /data/svn/myproject svnadmin create /data/s ...

  9. @Configuration与@Bean作用

    Spring的Java配置方式是通过@Configuration和@Bean这两个注解来实现 @Configuration可以作用在任意类上,表示该类是一个配置类,其实就相当于一个xml配置文件. @ ...

  10. Docker学习笔记之通过 Dockerfile 创建镜像

    0x00 概述 由于 Docker 镜像的结构优势,使它的占用空间远小于普通的虚拟机镜像,而这就大幅减少了 Docker 镜像在网络或者其他介质中转移所花费的时间,进而提高了我们进行迁移部署的效率.不 ...