设为首页 加入收藏

TOP

POJ 3686 The Windy's (一)
2015-11-21 01:21:52 来源: 作者: 【 】 浏览:11
Tags:POJ 3686 The Windy'

The Windy's
Time Limit: 5000MS?? Memory Limit: 65536K
Total Submissions: 3299?? Accepted: 1413

Description

The Windy's is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receives N orders for toys. The manager knows that every order will take different amount of hours in different workshops. More precisely, the i-th order will take Zij hours if the toys are making in the j-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 matrix Zij (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

3

3 4
100 100 100 1
99 99 99 1
98 98 98 1

3 4
1 100 100 100
99 1 99 99
98 98 1 98

3 4
1 100 100 100
1 99 99 99
98 1 98 98
Sample Output

2.000000
1.000000
1.333333

Source

POJ Founder Monthly Contest – 2008.08.31, windy7926778
[cpp]
/***************************************************************
??? > File Name:??? POJ3686.cpp
??? > Author:?????? SDUT_GYX
??? > Mail:???????? 2272902662@qq.com
??? > Created Time: 2013/6/4 0:16:38
?**************************************************************/?
?
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#include ??
#define LL long long??
#define N 3600??
#define inf 0x7ffffff??
using 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;?
??????????? }?
???????????

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 2488 A Knight's Journey 下一篇uva 11178 - Morley's Theore..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: