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

转载于:https://www.cnblogs.com/Khada-Jhin/p/9632977.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
校园失物招领系统管理系统按照操作主体分为管理员和用户。管理员的功能包括字典管理、论坛管理、公告信息管理、失物招领管理、失物认领管理、寻物启示管理、寻物认领管理、用户管理、管理员管理。用户的功能等。该系统采用了Mysql数据库,Java语言,Spring Boot框架等技术进行编程实现。 校园失物招领系统管理系统可以提高校园失物招领系统信息管理问题的解决效率,优化校园失物招领系统信息处理程,保证校园失物招领系统信息数据的安全,它是一个非常可靠,非常安全的应用程序。 ,管理员权限操作的功能包括管理公告,管理校园失物招领系统信息,包括失物招领管理,培训管理,寻物启事管理,薪资管理等,可以管理公告。 失物招领管理界面,管理员在失物招领管理界面中可以对界面中显示,可以对失物招领信息的失物招领状态进行查看,可以添加新的失物招领信息等。寻物启事管理界面,管理员在寻物启事管理界面中查看寻物启事种类信息,寻物启事描述信息,新增寻物启事信息等。公告管理界面,管理员在公告管理界面中新增公告,可以删除公告。公告类型管理界面,管理员在公告类型管理界面查看公告的工作状态,可以对公告的数据进行导出,可以添加新公告的信息,可以编辑公告信息,删除公告信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值