mcmf逆向思维。想成该车在第几个修会影响别人多少时间即可。拆点。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define clr(x,c) memset(x,c,sizeof(x))
#define qwq(x) for(edge *e=head[x];e;e=e->next)
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=705;
const int maxn=100000;
const int inf=0x7f7f7f7f;
struct edge{
int to,cap,cost;edge *next,*rev;
};
edge edges[maxn],*pt,*head[nmax],*p[nmax];
int d[nmax],a[nmax];bool inq[nmax];
queue<int>q;
void add(int u,int v,int d,int w){
pt->to=v;pt->cap=d;pt->cost=w;pt->next=head[u];head[u]=pt++;
}
void adde(int u,int v,int d,int w){
add(u,v,d,w);add(v,u,0,-w);head[u]->rev=head[v];head[v]->rev=head[u];
}
int mincost(int s,int t){
int cost=0;
while(1){
clr(inq,0);clr(d,0x7f);d[s]=0;inq[s]=1;a[s]=inf;q.push(s);
while(!q.empty()){
int x=q.front();q.pop();inq[x]=0;
qwq(x) if(e->cap>0&&d[e->to]>d[x]+e->cost){
int to=e->to;d[to]=d[x]+e->cost;
a[to]=min(a[x],e->cap);p[to]=e;
if(!inq[to]) q.push(to),inq[to]=1;
}
}
if(d[t]==inf) break;
cost+=d[t]*a[t];
int x=t;
while(x!=s) p[x]->cap-=a[t],p[x]->rev->cap+=a[t],x=p[x]->rev->to;
}
return cost;
}
int main(){
pt=edges;clr(head,0);
int m=read(),n=read(),s=0,t=n*m+n+1;
rep(i,n) rep(j,m){
int tmp=read();
rep(k,n) adde((j-1)*n+k,n*m+i,1,tmp*k);
}
rep(i,n) adde(n*m+i,t,1,0);
rep(i,n*m) adde(s,i,1,0);
printf("%.2lf
",(double)mincost(s,t)/n);
return 0;
}
1070: [SCOI2007]修车
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4493 Solved: 1853
[Submit][Status][Discuss]
Description
同一时刻有N位车主带着他们的爱车来到了汽车维修中心。维修中心共有M位技术人员,不同的技术人员对不同
的车进行维修所用的时间是不同的。现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待的时间最
小。 说明:顾客的等待时间是指从他把车送至维修中心到维修完毕所用的时间。
Input
第一行有两个m,n,表示技术人员数与顾客数。 接下来n行,每行m个整数。第i+1行第j个数表示第j位技术人
员维修第i辆车需要用的时间T。
Output
最小平均等待时间,答案精确到小数点后2位。
Sample Input
2 2
3 2
1 4
3 2
1 4
Sample Output
1.50
HINT
数据范围: (2<=M<=9,1<=N<=60), (1<=T<=1000)