Poj(3686),最小权匹配,多重匹配,KM

本文介绍了一种解决最小权匹配问题的方法,通过将问题转化为最大权匹配问题,并使用拆点等技巧来解决实际问题。文章提供了详细的算法步骤及C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

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;
}

转载于:https://www.cnblogs.com/TreeDream/p/5771976.html

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值