zoukankan      html  css  js  c++  java
  • BZOJ2557[Poi2011]Programming Contest——匈牙利算法+模拟费用流

    题目描述

    Bartie and his friends compete in the Team Programming Contest. There are n contestants on each team, and each team has access to n  computers. The contest lasts t minutes, during which the contestants are to solve m programming problems. Furthermore, penalties are imposed on the teams: solving a problem s minutes since the beginning of the contest amounts to  s penal points. The team that solved the most problems wins the contest, with ties broken in favour of the team with smaller penalty.
    On the contest day Bartie quickly glances over the problem statements and distributes them among his teammates. He knows his team so well that he can exactly assess who is able to solve which problem. Solving any problem takes any contestant that is able to solve it exactly r minutes of using the computer.
    Bartie's team did not fare well in this year's contest. Bartie is obsessed with the thought that it might be his fault, due to wrong decisions regarding the distribution of problems. He asks you to write a program that, given what Bartie knew at the beginning of the contest, determines the best possible result of Bytie's team, together with the assignment of problems to team members that attains the result.
    n个人m个题目,每个题要r分钟完成。比赛有t分钟。给出每个人会做哪些题目,请你安排一个每个人在什么时候做什么题目,使得做出来的题目数最多。在做题数一样多的情况下,罚时尽量小。

    输入

    Five integers n,m,r,t and k(1<=n,m<=500,1<=r,t<=10^6)) are given in the first line of the standard input, separated by single spaces. These denote, respectively: the number of contestants on a team, the number of problems, the time it takes a contestant to solve a problem, the duration of the contest, and the number of contestant-problem pairs given on the input. Each of the following k lines holds two integers a and b(1<=a<=n,1<=b<=m)), separated by a single space, denoting that the contestant a is able to solve the problem b. Each such pair appears at most once in the input.
    In tests worth at least 30% of the points it additionally holds that n,m<=100.

    输出

    In the first line of the standard output the best possible result of Bytie's team should be printed as two numbers separated by a single space: the number of solved problems z and the total penal points.

    样例输入

    2 4 3 15 4
    1 1
    2 3
    1 4
    1 3

    样例输出

    3 12
     
      要求最多做题数情况下的最小罚时,容易想到最小费用最大流,源点向每个人连费用为r,2r,3r……的边,题目连向汇点。但这样连边会达到百万,显然跑不过去。仔细观察能发现这个图的特殊性质,只有源点连向每个人的边有边权,而且是二分图。因此我们可以枚举时间,对于每r分钟枚举每个人来进行增广,如果当前这个人这次没有增广到,之后就不用再增广了。
    #include<map>
    #include<set>
    #include<queue>
    #include<cmath>
    #include<stack>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,m;
    int x,y;
    int tot;
    int ans;
    int cnt;
    int r,s,t;
    int v[510];
    bool vis[510];
    bool val[510];
    int head[510];
    int to[250010];
    int next[250010];
    void add(int x,int y)
    {
        tot++;
        next[tot]=head[x];
        head[x]=tot;
        to[tot]=y;
    }
    bool find(int x)
    {
        for(int i=head[x];i;i=next[i])
        {
            if(val[to[i]])
            {
                continue;
            }
            val[to[i]]=true;
            if(!v[to[i]]||find(v[to[i]]))
            {
                v[to[i]]=x;
                return true;
            }
        }
        return false;
    }
    int main()
    {
        scanf("%d%d%d%d%d",&n,&m,&r,&s,&t);
        while(t--)
        {
            scanf("%d%d",&x,&y);
            add(x,y);
        }
        for(int j=1;j<=s/r;j++)
        {
            for(int i=1;i<=n;i++)
            {
                if(!vis[i])
                {
                    memset(val,0,sizeof(val));
                    if(find(i))
                    {
                        cnt++;
                        ans+=j;
                    }
                    else
                    {
                        vis[i]=true;
                    }
                }
            }
        }   
        printf("%d %lld",cnt,1ll*ans*r);
    }
  • 相关阅读:
    [Oracle] CPU/PSU补丁安装教程
    VMware vSphere 服务器虚拟化之二十 桌面虚拟化之准备虚拟桌面模版
    我是如何写作一本软件+哲学式的书籍的(上)
    设计模式(二)-- 外观模式(Facade)
    PPT资料下载
    Ajax实现xml文件数据插入数据库(一)--- 构建解析xml文件的js库
    Ajax实现xml文件数据插入数据库(二)--- ajax实现与jsp的数据交互。
    iOS-王云鹤 APP首次启动显示用户指导
    控制文件的备份与恢复
    Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
  • 原文地址:https://www.cnblogs.com/Khada-Jhin/p/9632977.html
Copyright © 2011-2022 走看看