题目链接

The Windy's##

| Time Limit: 5000MS | Memory Limit: 65536K |

| Total Submissions: 4939 | Accepted: 2080 |

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

题意:###

有N个工件要在M个机器上加工,有一个N*M的矩阵描述其加工时间。同一时间内每个机器只能加工一个工件,问加工完所有工件后,使得平均加工时间最小。

分析:###

1, 首先,这是一个最小权匹配,但是我没写过,然后看了一下网上的结题报告,又问了一下阳哥,发现,最小权匹配可以转换为最大权匹配,权值改为负数就可以了

2, 然后是拆点,分块,每一个机器都对应了nx个玩具。

3, 这里是最难的地方了。我也是看了结题报告才知道怎么处理这里,就是说可能一个机器加工多个玩具,比如说k个,耗时为a1,(a1+a2),(a1+a2+a3),......(a1+a2+......+ak);

那么,对于一个玩具(例如a1),他所贡献的时间其实为a1乘k,我们可以发现规律,对于倒数第k的玩具,他贡献的耗时为k*a1,那么拆点的时候,就应该是a1,a1乘2,......

当做模板好好学习吧!!!

Code(C++):##

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; #define MAXN 55
#define inf 0x7ffffff int w[MAXN][2555];
int lx[MAXN],ly[2555];
int linky[2555];
int visx[MAXN],visy[2555];
int slack[2555];
int nx,ny;
int n,m; bool find(int x)
{
visx[x]=1;
for(int y=1;y<=ny;y++)
{
if(visy[y]) continue;
int t=lx[x]+ly[y]-w[x][y];
if(t==0)
{
visy[y]=1;
if(linky[y] ==-1 || find(linky[y]))
{
linky[y]=x;
return true;
}
}
else if(slack[y] > t)
slack[y]=t;
}
return false;
} int KM()
{
memset(linky,-1,sizeof(linky));
memset(ly,0,sizeof(ly));
for(int i=1;i<=nx;i++)
{
lx[i]=-inf;
for(int j=1;j<=ny;j++)
if(w[i][j] >lx[i])
lx[i]=w[i][j];
}
for(int x=1;x<=nx;x++)
{
for(int i=1;i<=ny;i++)
slack[i]=inf;
while(1)
{
memset(visx,0,sizeof(visx));
memset(visy,0,sizeof(visy));
if(find(x)) break;
int d=inf;
for(int i=1;i<=ny;i++)
if(!visy[i] && d>slack[i])
d=slack[i];
for(int i=1;i<=nx;i++)
if(visx[i])
lx[i]-=d;
for(int i=1;i<=ny;i++)
if(visy[i])
ly[i]+=d;
else
slack[i]-=d;
}
}
int ans=0;
for(int i=1;i<=ny;i++)
if(linky[i] >-1)
ans+=w[linky[i]][i];
return -ans;
} void init()
{
scanf("%d%d",&n,&m);
nx=n;
ny=n*m;
int cost;
for(int i=1;i<=n;i++)
{
int cnt=1;
for(int j=1;j<=m;j++)
{
scanf("%d",&cost);
for(int k=1;k<=n;k++)
{
w[i][cnt++]=-cost*k;
}
}
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
double ans=1.0*KM()/n;
printf("%.6f\n",ans);
}
return 0;
}

Poj(3686),最小权匹配,多重匹配,KM的更多相关文章

  1. POJ 2400 最小权匹配

    吐槽:首先,这道题的输入居然是错的.要将上下两个矩阵的位置换一下才可以出样例,也就是上面那个矩阵是employee对Supervisor的打分,下面那个矩阵才是Supervisor对employee的 ...

  2. Poj 3189 Steady Cow Assignment (多重匹配)

    题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...

  3. POJ 2112—— Optimal Milking——————【多重匹配、二分枚举答案、floyd预处理】

    Optimal Milking Time Limit:2000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Sub ...

  4. [ACM] POJ 3686 The Windy&#39;s (二分图最小权匹配,KM算法,特殊建图)

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4158   Accepted: 1777 Descr ...

  5. poj 3686(拆点+最小权匹配)

    题目链接:http://poj.org/problem?id=3686 思路:显然工件为X集,机器为Y集合.由于每个机器一次只能加工一个部件,因此我们可以将一台机器拆成N个点,至于部件与机器之间连多大 ...

  6. poj 2195(KM求最小权匹配)

    题目链接:http://poj.org/problem?id=2195 思路:我们都知道KM使用来求最大权匹配的,但如果要求最小权匹配,只需把图中的权值改为负值,求一次KM,然后权值和取反即可. ht ...

  7. 【POJ 2400】 Supervisor, Supervisee(KM求最小权匹配)

    [POJ 2400] Supervisor, Supervisee(KM求最小权匹配) Supervisor, Supervisee Time Limit: 1000MS   Memory Limit ...

  8. 【POJ 2195】 Going Home(KM算法求最小权匹配)

    [POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  9. poj3565 Ants km算法求最小权完美匹配,浮点权值

    /** 题目:poj3565 Ants km算法求最小权完美匹配,浮点权值. 链接:http://poj.org/problem?id=3565 题意:给定n个白点的二维坐标,n个黑点的二维坐标. 求 ...

随机推荐

  1. Swift游戏实战-跑酷熊猫 14 熊猫打滚

    这节内容我们来实现熊猫打滚.思路是这样的,当熊猫起跳时记录他的Y坐标,落到平台上的时候再记录它的Y坐标.两个坐标之间的差要是大于一定数值就判断它从高处落下要进行打滚缓冲.至此跑酷熊猫已经像一个游戏的样 ...

  2. PostgreSQL Replication之第九章 与pgpool一起工作(6)

    9.6 运行pgpool和流复制 pgpool也可以和除了语句级别的复制之外的流复制一起使用.一个完美的方案是使用PostgreSQL的板载复制和仅仅使用pgpool的负载均衡与连接池. 实际上,这样 ...

  3. Lintcode: Search Range in Binary Search Tree

    Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all t ...

  4. mysql linux 备份脚本

    #!/bin/sh # mysql data backup script # # use mysqldump --help,get more detail. # BakDir=/root/back/m ...

  5. 实现listview的条目点击后改变背景颜色

    gv_categoryeffect_gridview.setChoiceMode(GridView.CHOICE_MODE_SINGLE);,再设置一个selector的背景选择器 getResour ...

  6. 把所有特权给root '%'所有IP

    grant all privileges on *.* to root@'%' identified by 'root'; --把所有特权给root '%'所有IP

  7. 夺命雷公狗ThinkPHP项目之----企业网站22之网站前台中间层(解决代码冗余)

    我们如果这样写代码虽然可以实现头部二级分类的显示,但是如果再别的控制器下那么会出现显示不了.. 如果再加多一段一样的代码也可以实现出一样的效果: 但是这样会导致代码冗余现象,所以我们为了解决这个问题, ...

  8. [Ubuntu] Ubuntu搭建VPN服务器pptpd

    在 Ubuntu 上搭建 VPN 服务器的方法非常多,比较著名的有 PPTP, L2TP/IPSec 和 OpenVPN. 这三种方式中后两者的安全性比较好,但配置较麻烦.其中 OpenVPN 在 W ...

  9. java 网络编程(三)---TCP的基础级示例

    下面是TCP java网络编程的基础示例: tcp传输:客户端建立过程的思路:1.创建TCP客户端的Socket服务,使用的是socket对象,建议在创建的过程中,就明确了目的地和要连接的主机2.如果 ...

  10. SQL SERVER 2008 R2配置管理器出现“远程过程调用失败”【0x800706be】的解决办法

    以前SQL Server 2008 不能登陆的时候,总是通过“计算机管理”→“SQL Server服务”更改一下,"SQL Server(MSSQLSERVER)".可是现在出现的 ...