POJ 3686 The Windy's
来源:互联网 发布:剑灵人女捏脸数据图表 编辑:程序博客网 时间:2024/05/16 10:20
Description
The Windy's is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receivesN orders for toys. The manager knows that every order will take different amount of hours in different workshops. More precisely, thei-th order will take Zij hours if the toys are making in thej-th workshop. Moreover, each order's work must be wholly completed in the same workshop. And a workshop can not switch to another order until it has finished the previous one. The switch does not cost any time.
The manager wants to minimize the average of the finishing time of the N orders. Can you help him?
Input
The first line of input is the number of test case. The first line of each test case contains two integers,N and M (1 ≤ N,M ≤ 50).
The next N lines each contain M integers, describing the matrixZij (1 ≤ Zij ≤ 100,000) There is a blank line before each test case.
Output
For each test case output the answer on a single line. The result should be rounded to six decimal places.
Sample Input
33 4100 100 100 199 99 99 198 98 98 13 41 100 100 10099 1 99 9998 98 1 983 41 100 100 1001 99 99 9998 1 98 98
Sample Output
2.0000001.0000001.333333
Source
/***************************************************************> File Name: POJ3686.cpp> Author: SDUT_GYX> Mail: 2272902662@qq.com> Created Time: 2013/6/4 0:16:38 **************************************************************/#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <queue>#include <cstdlib>#include <iomanip>#include <string>#include <vector>#include <map>#include <cmath>#include <stack>#define LL long long#define N 3600#define inf 0x7ffffffusing namespace std;int lx[N],ly[N],slack[N],linky[N],w[N][N],n,m;bool visitx[N],visity[N];int main(){//freopen("data1.in","r",stdin);int KM();int t;scanf("%d",&t);while(t--){scanf("%d %d",&n,&m);int x;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){scanf("%d",&x);for(int k=1;k<=n;k++){w[i][(j-1)*n + k] = -x*k;}}}m=n*m;int res=KM();printf("%.6lf\n",(double)res/n);}return 0;}bool find(int k){visitx[k] = true;for(int i=1;i<=m;i++){if(visity[i]){continue;}int t=lx[k] + ly[i] - w[k][i];if(t==0){visity[i] = true;if(!linky[i]||find(linky[i])){linky[i] = k;return true;}}else {slack[i]=min(slack[i],t);}}return false;}int KM(){memset(ly,0,sizeof(ly));memset(linky,0,sizeof(linky));for(int i=1;i<=n;i++){lx[i] = -inf;}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){lx[i] = max(lx[i],w[i][j]);}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){slack[j] = inf;}while(1){memset(visitx,false,sizeof(visitx));memset(visity,false,sizeof(visity));if(find(i)){break;}int d=inf;for(int i=1;i<=m;i++){if(!visity[i]){d = min(d,slack[i]);}}for(int i=1;i<=n;i++){if(visitx[i]){lx[i] -=d;}}for(int i=1;i<=m;i++){if(visity[i]){ly[i] +=d;}else{slack[i] -=d;}}}}int s=0;for(int i=1;i<=m;i++){if(linky[i]){int j=linky[i]; s+=w[j][i];}}return -s;}
- poj 3686 The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's
- POJ-3686-The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's
- poj 3686 The Windy's
- poj 3686 The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's KM算法
- The Windy's - POJ 3686 KM算法
- Poj 3686 The Windy's【KM匹配】
- POJ 3686 The Windy's 笔记
- POJ--3686[The Windy's] 最小费用流或KM
- POJ 3686 The Windy's & HDU 3718 Similarity
- poj 3686 The Windy's(最小费用最大流)
- DSP芯片的定点运算
- Junit4中怎样随心所欲的执行Test(二)
- C++学习_关联容器(map,set)
- HDU 2020
- Android_WebView用法
- POJ 3686 The Windy's
- MySQL NOW() 函数
- Android--AlertDialog的用法
- Android--ScrollView只能添加一个子控件问题
- VS2010+DB2连接
- RTC 3.0.1.5升级至3.0.1.6
- JSP和Servlet面试题精选
- CocosBuilder(二)绑定自定义类
- MySql外键关联Foreign key及error 1452