Title Description
The same time there are N car owners with their car came to a car repair center. M service center has technical staff, technical staff of various different car repair time used is different. Now need to arrange this M bit of skill in the repair of cars and order so that the average customer wait time to a minimum.
Description: Customer wait time is the time the service is completed with from his car to a service center to.
Input Format
The first line has two numbers M, N, and the number represents the number of customers in the art.
Next n lines of m integers. I + 1 th row and j represents the number of times j-th bit of the i-maintenance technicians need to use vehicle T.
Output Format
The minimum average waiting time, accurate answers to two decimal places.
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e4+10,M=2e5+10,inf=0x3f3f3f3f;
int n,m,s,t;
int nxt[M],head[N],go[M],edge[M],cost[M],tot=1;
inline void add(int u,int v,int o1,int o2){
nxt[++tot]=head[u],head[u]=tot,go[tot]=v,edge[tot]=o1,cost[tot]=o2;
nxt[++tot]=head[v],head[v]=tot,go[tot]=u,edge[tot]=0,cost[tot]=-o2;
}
int dis[N],ret;
bool vis[N];
inline bool spfa(){
memset(dis,0x3f,sizeof(dis)); dis[s]=0;
queue<int>q; q.push(s);
while(q.size()){
int u=q.front(); q.pop(); vis[u]=0;
for(int i=head[u];i;i=nxt[i]){
int v=go[i];
if(edge[i]&&dis[v]>dis[u]+cost[i]){
dis[v]=dis[u]+cost[i];
if(!vis[v])q.push(v),vis[v]=1;
}
}
}
return dis[t]!=inf;
}
int dinic(int u,int flow){
if(u==t)return flow;
int rest=flow,k;
vis[u]=1;
for(int i=head[u];i&&rest;i=nxt[i]){
int v=go[i];
if(edge[i]&&!vis[v]&&dis[v]==dis[u]+cost[i]){
k=dinic(v,min(rest,edge[i]));
if(!k)dis[v]=-1;
ret+=k*cost[i];
edge[i]-=k;
edge[i^1]+=k;
rest-=k;
}
}
vis[u]=0;
return flow-rest;
}
int c[65][65];
signed main(){
cin>>m>>n;
t=n*m+n+1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&c[i][j]);
for(int i=1;i<=n*m;i++)add(s,i,1,0);
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++){
int now=(i-1)*n+k;
add(now,j+n*m,1,c[j][i]*k);
}
for(int i=1;i<=n;i++)add(n*m+i,t,1,0);
int flow=0,maxflow=0;
while(spfa())
while(flow=dinic(s,inf))maxflow+=flow;
printf("%.2lf\n",1.0*ret/n);
}