题目描述

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

BZOJ2557[Poi2011]Programming Contest——匈牙利算法+模拟费用流的更多相关文章

  1. BZOJ3291Alice与能源计划——匈牙利算法+模拟费用流

    题目描述 在梦境中,Alice来到了火星.不知为何,转眼间Alice被任命为火星能源部长,并立刻面临着一个严峻的考验.为 了方便,我们可以将火星抽象成平面,并建立平面直角坐标系.火星上一共有N个居民点 ...

  2. 【bzoj3291】Alice与能源计划 模拟费用流+二分图最大匹配

    题目描述 在梦境中,Alice来到了火星.不知为何,转眼间Alice被任命为火星能源部长,并立刻面临着一个严峻的考验. 为了方便,我们可以将火星抽象成平面,并建立平面直角坐标系.火星上一共有N个居民点 ...

  3. 【CF280D】 k-Maximum Subsequence Sum ,线段树模拟费用流

    昨天考试被教育了一波.为了学习一下\(T3\)的科技,我就找到了这个远古时期的\(cf\)题(虽然最后\(T3\)还是不会写吧\(QAQ\)) 顾名思义,这个题目其实可以建成一个费用流的模型.我们用流 ...

  4. 模拟费用流 & 可撤销贪心

    1. CF730I Olympiad in Programming and Sports 大意: $n$个人, 第$i$个人编程能力$a_i$, 运动能力$b_i$, 要选出$p$个组成编程队, $s ...

  5. [NOI2019]序列(模拟费用流)

    题意: 有两个长度为n的序列,要求从每个序列中选k个,并且满足至少有l个位置都被选,问总和最大是多少. \(1\leq l\leq k\leq n\leq 2*10^5\). 首先,记录当前考虑到的位 ...

  6. BZOJ 3836 Codeforces 280D k-Maximum Subsequence Sum (模拟费用流、线段树)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=3836 (Codeforces) http://codeforces.com ...

  7. UOJ #455 [UER #8]雪灾与外卖 (贪心、模拟费用流)

    题目链接 http://uoj.ac/contest/47/problem/455 题解 模拟费用流,一个非常神奇的东西. 本题即为WC2019 laofu的讲课中的Problem 8,经典的老鼠进洞 ...

  8. 贪心(模拟费用流):NOIP2011 观光公交

    [问题描述] 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0 分钟出现在1号景点,随后依次前往2. ...

  9. BZOJ4977[Lydsy1708月赛]跳伞求生——贪心+堆+模拟费用流

    题目链接: 跳伞求生 可以将题目转化成数轴上有$n$个人和$m$个房子,坐标分别为$a_{i}$和$b_{i}$,每个人可以进一个他左边的房子,每个房子只能进一个人.每个房子有一个收益$c_{i}$, ...

随机推荐

  1. highcharts中把X轴的名字竖着显示

    Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Auto rotation limit' }, s ...

  2. virtualbox - 2台虚拟机之间通过ssh互访

    virtualbox 5.2.12 一台虚拟机是Debian 9,另一台是Ubuntu 18.04. 注意: 2台虚拟机系统里要安装ssh ! sudo apt install ssh 然后在virt ...

  3. Luogu4345 SHOI2015 超能粒子炮·改 Lucas、数位DP

    传送门 模数小,还是个质数,Lucas没得跑 考虑Lucas的实质.设\(a = \sum\limits_{i=0}^5 a_i 2333^i\),\(b = \sum\limits_{i=0}^5 ...

  4. 重装系统之制作U盘启动盘

    准备: 1.需要一个大于4G的U盘. 2.一个原版系统. 3.制作U盘启动盘的工具—ultraliso. 一.一个大于4G的U盘 制作启动盘将会格式化U盘,记得做好备份. 二.一个原版系统 至于你要装 ...

  5. 谈谈css伪类与伪元素

    前端er们大都或多或少地接触过CSS伪类和伪元素,比如最常见的:focus.:hover以及<a>标签的:link.:visited等,伪元素较常见的比如:before.:after等. ...

  6. PyCharm Tips 常用操作帮助

    以下内容转自 http://www.2cto.com/os/201410/341542.html --------------------------------------------------- ...

  7. Python-集合-17

    ''' 集合:可变的数据类型,他里面的元素必须是不可变的数据类型,无序,不重复. {} ''' set1 = set({1,2,3}) # set2 = {1,2,3,[2,3],{'name':'a ...

  8. eclipse集成tomcat日志文件输出配置

    eclipse集成tomcat日志文件输入配置 2015-07-21 00:13 1072人阅读 评论(0) 收藏 举报  分类: tomcat(1)  eclipse Where can I vie ...

  9. JavaScript模拟表单(带数组的复杂数据结构)提交

    function test(){    var typeArray = new Array();    typeArray.push("mm");    typeArray.pus ...

  10. Selenium自动化测试框架

    如下图所示,为公司搭建的基于Selenium+Ant+TestNG+Jenkins的持续集成的自动化测试框架. Selenium: Page Object Model+Data Driver(Exce ...