[SCOI2007]修车 费用流 BZOJ 1070
题目描述
同一时刻有N位车主带着他们的爱车来到了汽车维修中心。维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的。现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待的时间最小。
说明:顾客的等待时间是指从他把车送至维修中心到维修完毕所用的时间。
输入输出格式
输入格式:
第一行有两个数M,N,表示技术人员数与顾客数。
接下来n行,每行m个整数。第i+1行第j个数表示第j位技术人员维修第i辆车需要用的时间T。
输出格式:
最小平均等待时间,答案精确到小数点后2位。
输入输出样例
说明
(2<=M<=9,1<=N<=60), (1<=T<=1000)
假设对于某一个技术工人来说,维修序列为:
w1,w2,w3...,wn;
那么等待的时间:
T=n*w1+(n-1)*w2+...+wn;
可见费用(消耗的时间)与位置有关;
那么我们将技术工拆点,拆成 n 个;
然后建边的时候分别设立不同的费用,最后跑一下最小费用最大流;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 20005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ bool vis[maxn];
int n, m, s, t;
int x, y, f, z;
int dis[maxn], pre[maxn], last[maxn], flow[maxn];
int maxflow, mincost; struct node {
int to, nxt, flow, cost;
}edge[maxn<<2]; int head[maxn], cnt;
queue<int>q; void addedge(int from, int to, int flow, int cost) {
edge[++cnt].to = to; edge[cnt].flow = flow; edge[cnt].cost = cost;
edge[cnt].nxt = head[from]; head[from] = cnt;
} bool spfa(int s, int t) {
memset(dis, 0x7f, sizeof(dis)); memset(flow, 0x7f, sizeof(flow));
ms(vis);
q.push(s); vis[s] = 1; dis[s] = 0; pre[t] = -1;
while (!q.empty()) {
int now = q.front(); q.pop(); vis[now] = 0;
for (int i = head[now]; i != -1; i = edge[i].nxt) {
if (edge[i].flow > 0 && dis[edge[i].to] > dis[now] + edge[i].cost) {
int v = edge[i].to;
dis[v] = dis[now] + edge[i].cost;
pre[v] = now; last[v] = i;
flow[v] = min(flow[now], edge[i].flow);
if (!vis[v]) {
vis[v] = 1; q.push(v);
}
}
}
}
return pre[t] != -1;
} void mincost_maxflow() {
while (spfa(s, t)) {
int now = t;
maxflow += flow[t]; mincost+=flow[t] * dis[t];
while (now != s) {
edge[last[now]].flow -= flow[t];
edge[last[now] ^ 1].flow += flow[t];
now = pre[now];
}
}
} int main() {
//ios::sync_with_stdio(0);
memset(head, -1, sizeof(head)); cnt = 1;
rdint(m); rdint(n);
s = 1000; t = s + 1;
for (int i = 1; i <= n; i++)addedge(s, i, 1, 0), addedge(i, s, 0, 0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int tmp; rdint(tmp);
for (int k = 1; k <= n; k++) {
addedge(i, j*n + k, 1, tmp*k); addedge(j*n + k, i, 0, -tmp * k);
}
}
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++)addedge(i*n + j, t, 1, 0), addedge(t, i*n + j, 0, 0);
}
mincost_maxflow();
printf("%.2lf\n", 1.0*mincost / n);
return 0;
}
[SCOI2007]修车 费用流 BZOJ 1070的更多相关文章
- bzoj 1070: [SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2785 Solved: 1110[Submit][Status] ...
- 【BZOJ 1070】[SCOI2007]修车 费用流
就是拆个点限制一下(两点一排一大片),这道题让我注意到了限制这个重要的词.我们跑网络流跑出来的图都是有一定意义的,一般这个意义就对应了问题的一种方案,一般情况下跑一个不知道对不对的方案是相对容易的我们 ...
- [BZOJ1070][SCOI2007]修车 费用流
1070: [SCOI2007]修车 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 6209 Solved: 2641[Submit][Status] ...
- 【BZOJ1070】[SCOI2007]修车 费用流
[BZOJ1070][SCOI2007]修车 Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. ...
- P2053 [SCOI2007]修车 费用流
$ \color{#0066ff}{ 题目描述 }$ 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M ...
- [bzoj1070][SCOI2007]修车——费用流
题目大意: 传送门 题解: 本题和(POJ3686)[http://poj.org/problem?id=3686]一题一模一样,而且还是数据缩小以后的弱化版QAQ,<挑战程序设计竞赛>一 ...
- [BZOJ1070] [SCOI2007] 修车 (费用流 & 动态加边)
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使 ...
- BZOJ.1070.[SCOI2007]修车(费用流SPFA)
题目链接 /* 神tm看错题*2.. 假如人员i依次维修W1,W2,...,Wn,那么花费的时间是 W1 + W1+W2 + W1+W2+W3... = W1*n + W2*(n-1) + ... + ...
- [SCOI2007]修车 费用流
---题面--- 题解: 因为我们并不需要知道准确方案,而人数固定,要使得平均等待时间最小,也就是要使得总的等待时间最小. 因此我们将工人按每个时刻拆点,拆完之后向车子连边,流量为1,费用为k * 维 ...
随机推荐
- 用cookie登录慕课网络教学中心刷评论
声明:本文仅供学习参考 我们学校和的网络教学平台是在慕课网上的,需要登录到慕课网的教学平台以后,拿到cookie 注意:没次提交后需要休眠,否则刷评论过快会被系统发现 如果请求太快,很容易被系统发现( ...
- BEC listen and translation exercise 47
Site One was unpopular because of traffic and parking problems.场地一由于交通和停车问题而不受欢迎. The bombs killed a ...
- PS 滤镜——(扭曲)球面化 Spherize
%%%% Spherize clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorit ...
- 【leetcode刷题笔记】Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- thinkphp中图片上传的几种好的办法
http://www.thinkphp.cn/code/701.html http://www.thinkphp.cn/code/151.html
- CCS V5 使用教程三:程序调试
官网教程 新建调试工程 输入以下源码: #include <stdio.h> #include <c6x.h> ]; void main(void) { unsigned ; ...
- 【转】 Pro Android学习笔记(六一):Preferences(5):组织Preference
目录(?)[-] PreferenceCategory Child Preference PreferenceCategory 如果有多个preference,我们希望能在他们组织在一起.有两种方式, ...
- CUDA V9.2 sample编译问题
这个哥们也遇到一样的问题 CUDA 9.1/9.2 与 Visual Studio 2017 (VS2017 15.6.4) 的不兼容问题 错误有显示 #if _MSC_VER < 1600 | ...
- for循环及break和continue的区别
1.For循环 格式: for( 初始语句 ; 执行条件 ; 增量 ){ 循环体 } 执行顺序:1.初始语句 2.执行条件是否符合 3.循环体 4.增加增量 初始化语句只在循环开始前执行一次,每次 ...
- Nmap几个常用的参数
Nmap扫描端口的6种状态: open:端口是开放的 closed:端口是关闭的 filtered:端口被防火墙IDS/IPS屏蔽,无法确定其状态 unfiltered:端口没有被屏蔽,但要进一步确定 ...