[bzoj1070][SCOI2007]修车[ 网络流]
把每个工人拆成N个点。记为A[i,j]表示第i个工人修倒数第j辆车.每个车跟所有N*M个工人拆出的点连边。流量为1,费用为$time[i,j]*k$。源和每辆车连边,N*M个点和汇连边,流量都为1,费用同为0。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <queue> using namespace std; template<const int _n,const int _m>
struct Edge
{
struct Edge_base { int to,next,w,c; }e[_m]; int cnt,p[_n];
void clear() { cnt=,memset(p,,sizeof(p)); }
Edge() { clear(); }
void insert(const int x,const int y,const int z,const int zz)
{ e[++cnt].to=y; e[cnt].next=p[x]; e[cnt].w=z; e[cnt].c=zz; p[x]=cnt; return ; }
void link(const int x,const int y,const int z,const int zz)
{ insert(x,y,z,zz); insert(y,x,,-zz); }
int start(const int x) { return p[x]; }
Edge_base& operator[](const int x) { return e[x]; }
}; int n,m,Time[][],SSS,TTT,Cost;
int Dis[],cur[];
bool visited[];
Edge<,>e; bool Spfa(const int S)
{
int i,t,temp;
queue<int> Q;
memset(Dis,0x3f,sizeof(Dis));
Dis[S]=;
visited[S]=true;
Q.push(S);
while(!Q.empty())
{
t=Q.front();Q.pop();visited[t]=false;
for(i=e.start(t);i;i=e[i].next)
{
temp=e[i].to;
if(e[i].w && Dis[t]+e[i].c<Dis[temp])
{
Dis[temp]=Dis[t]+e[i].c;
if(!visited[temp])
{
visited[temp]=true;
Q.push(temp);
}
}
}
}
return Dis[TTT]!=0x3f3f3f3f;
} int Dfs(const int S,const int bk)
{
visited[S]=true;
if(S==TTT)return bk;
int rest=bk;
for(int &i=cur[S];i;i=e[i].next)
{
if(!visited[e[i].to] && Dis[S]+e[i].c==Dis[e[i].to] && e[i].w)
{
int flow=Dfs(e[i].to,min(rest,e[i].w));
Cost+=flow*e[i].c;
e[i].w-=flow;
e[i^].w+=flow;
if((rest-=flow)<=)break;
}
}
if(bk==rest)Dis[S]=0x3f3f3f3f;
return bk-rest;
} int Zkw()
{
while(Spfa(SSS))
{
do
{
memset(visited,,sizeof(visited));
memcpy(cur,e.p,sizeof(cur));
Dfs(SSS,0x3f3f3f3f);
}while(visited[TTT]);
}
return Cost;
} int main()
{
int i,j,k; scanf("%d%d",&n,&m);
for(i=;i<=m;++i)
for(j=;j<=n;++j)
scanf("%d",&Time[i][j]);
SSS=n*m+m+,TTT=SSS+;
for(i=;i<=n*m;++i)e.link(SSS,i,,);
for(i=n*m+;i<SSS;++i)e.link(i,TTT,,);
for(k=;k<=m;++k)
for(i=;i<=n;++i)
for(j=;j<=m;++j)
e.link((i-)*m+j,n*m+k,,Time[k][i]*j);
printf("%.2lf\n",(double)Zkw()/m);
return ;
}
[bzoj1070][SCOI2007]修车[ 网络流]的更多相关文章
- [bzoj1070][SCOI2007]修车_费用流
修车 bzoj-1070 SCOI-2007 题目大意:有m个人要修n台车,每个工人修不同的车的时间不同,问将所有的车都修完,最少需要花费的时间. 注释:$2\le m\le 9$,$1\le n \ ...
- [BZOJ1070][SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 6209 Solved: 2641[Submit][Status] ...
- bzoj1070: [SCOI2007]修车(费用流)
1070: [SCOI2007]修车 题目:传送门 题解: 一道挺简单的费用流吧...胡乱建模走起 贴个代码... #include<cstdio> #include<cstring ...
- BZOJ1070: [SCOI2007]修车(最小费用最大流,思维)
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同 的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序, ...
- BZOJ1070 [SCOI2007]修车
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- 洛谷$P2053\ [SCOI2007]$修车 网络流
正解:网络流 解题报告: 传送门$QwQ$ 一个很妙的建图,,,说实话我麻油想到$QwQ$ 考虑对每个工人建$n$个点,表示这是他修的倒数第$i$辆车,就可以算出影响是$t\cdot i$,然后对每辆 ...
- [BZOJ1070][SCOI2007]修车(最小费用最大流)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1070 分析: 把每个工人拆成N个点.记为A[i,j]表示第i个工人修倒数第j辆车. 每 ...
- [bzoj1070][SCOI2007]修车——费用流
题目大意: 传送门 题解: 本题和(POJ3686)[http://poj.org/problem?id=3686]一题一模一样,而且还是数据缩小以后的弱化版QAQ,<挑战程序设计竞赛>一 ...
- [BZOJ1070] [SCOI2007] 修车 (费用流 & 动态加边)
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使 ...
随机推荐
- HTML5常用知识点
github代码:https://github.com/showkawa/H5C3/tree/master/html5 1.自定义属性 data- 1.1 可以给html里的所有DOM对象都可以添加一 ...
- 获取openid [微信小程序]
public function wxapi(){ $data=$this->requestdata(); if(!$data['code']) exit(json_encode(array('s ...
- linux守护进程的编写
linux监控一个进程进行 代码如下: #!/bin/sh cd /home/autoprocess/ auto=`pgrep -f autoProcessNew.php | wc -l` if [ ...
- spring 嵌套事务问题
嵌套事物总结 事物成功总结 1.内外都无try Catch的时候,外部异常,全部回滚. 2.内外都无try Catch的时候,内部异常,全部回滚. 3.外部有try Catch时候,内部异常,全部回滚 ...
- Office Excel的几个快捷键记录
Office Excel的几个快捷键记录: 切换Sheet:CTRL + PageUP/PageDown 另存为:F12
- 四种IO模型
四种 IO 模型: 首先需要明确,IO发生在 用户进程 与 操作系统 之间.可以是客户端IO也可以是服务器端IO. 阻塞IO(blocking IO): 在linux中,默认情况下 ...
- 236 Lowest Common Ancestor of a Binary Tree 二叉树的最近公共祖先
给定一棵二叉树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tre ...
- .net环境下程序一些未知错误的调试
由于线程冲突等一系列原因导致的处理调试方法 1.打开[事件查看器]查找出错误的地方 [控制面板]-[系统和安全]-[管理工具]-[事件查看器]
- jQuery实现文字横向滚动效果
HTML代码: <div id="aaa" style="width:100px; position:relative; white-space:nowrap; o ...
- 网页添加qq咨询
<style>.box{ width:130px; height:150px; position:fixed; right:0px; top:30%; z-index:999; borde ...