博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ2557[Poi2011]Programming Contest——匈牙利算法+模拟费用流
阅读量:6280 次
发布时间:2019-06-22

本文共 3319 字,大约阅读时间需要 11 分钟。

题目描述

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#include
#include
#include
#include
#include
#include
#include
#include
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

你可能感兴趣的文章
document.createElement
查看>>
Outlook Anywhere 客户端配置详解
查看>>
Go语言学习资料整理
查看>>
精进不休 .NET 4.0 (3) - asp.net 4.0 新特性之动态数据(Dynamic Data)增强
查看>>
麻将游戏
查看>>
用“ICET”轻松诊断 Windows 7 网络连接高级功能
查看>>
在MPAndroidChart库K线图的基础上画均线
查看>>
Gradle 1.12用户指南翻译——第四十四章. 分发插件
查看>>
查询远程或本地计算机的登录账户
查看>>
chk cloud
查看>>
asp.net事件顺序
查看>>
即时数据模块设计 版本V2
查看>>
CCNP-6 OSPF试验2(BSCI)
查看>>
Excel 2013 全新的图表体验
查看>>
openstack 制作大于2TB根分区自动扩容的CENTOS镜像
查看>>
Unbuntu安装遭遇 vmware上的Easy install模式
查看>>
几个常用的ASP木马
查看>>
python分析postfix邮件日志的状态
查看>>
Mysql-5.6.x多实例配置
查看>>
psutil
查看>>