2015-2016 ACM-ICPC Nordic Collegiate Programming Contest ---E题Entertainment Box(有点变化的贪心)
提交链接
http://codeforces.com/gym/100781/submit
Description:
Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fights they have finally decided to buy a video tape recorder. This fabulous, new device can record k different TV shows simultaneously, and whenever a show recorded in one the machine’s k slots ends, the machine is immediately ready to record another show in the same slot.
The three friends wonder how many TV shows they can record during one day. They provide you with the TV guide for today’s shows, and tell you the number of shows the machine can record simultaneously. How many shows can they record, using their recording machine? Count only shows that are recorded in their entirety.
Input
The first line of input contains two integers n, k (1 ≤ k < n ≤ 100 000). Then follow n lines, each containing two integers xi , yi , meaning that show i starts at time xi and finishes by time yi . This means that two shows i and j, where yi = xj , can be recorded, without conflict, in the same recording slot. You may assume that 0 ≤ xi < yi ≤ 1 000 000 000.
Output
The output should contain exactly one line with a single integer: the maximum number of full shows from the TV guide that can be recorded with the tape recorder.
Sample 1:
3 1
1 2
2 3
2 3
2
Sample 2:
4 1
1 3
4 6
7 8
2 5
3
Sample 3:
5 2
1 4
5 9
2 7
3 8
6 10
3
题意:输入n,k 表示有n场电视节目,最多可以同时录制k场,然后n行输入电视节目的起始时间和结束时间,注意(x1,y1) (x2,y2) y1==x2 不算重叠,求能录制的最多数量;
思路:定义多重集合 multiset<int>q; 插入k个0,表示同时录制时已经录制完部分电视节目的结束时间,把n个电视节目按结束时间排序,依次进行处理,如果当前电视节目的起始时间比集合中的k个数都要小,则表示当前节目不能放在k个节目任何一个节目后录制,则跳过;否则,在k个结束时间中找一个小于等于(最接近的,贪心原则)当前节目开始时间的值,然后删掉更新为当前节目的结束时间;
感悟:我做这道题时,一直没往这个方向想,唉,太智障了~
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
struct Node
{
int s,e;
}node[];
bool cmp(const Node x,const Node y)
{
if(x.e==y.e) return x.s>y.s;
return x.e<y.e;
}
multiset<int>q;
multiset<int>::iterator it;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
q.clear();
for(int i=;i<n;i++)
scanf("%d%d",&node[i].s,&node[i].e);
sort(node,node+n,cmp);
for(int i=;i<k;i++)
q.insert();
int sum=;
for(int i=;i<n;i++)
{
it=q.upper_bound(node[i].s);
if(it==q.begin()) continue;
it--;
q.erase(it);
q.insert(node[i].e);
sum++;
}
cout<<sum<<endl;
}
}
2015-2016 ACM-ICPC Nordic Collegiate Programming Contest ---E题Entertainment Box(有点变化的贪心)的更多相关文章
- ACM ICPC, JUST Collegiate Programming Contest (2018) Solution
A:Zero Array 题意:两种操作, 1 p v 将第p个位置的值改成v 2 查询最少的操作数使得所有数都变为0 操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...
- ACM ICPC, Amman Collegiate Programming Contest (2018) Solution
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...
- Nordic Collegiate Programming Contest 2015 B. Bell Ringing
Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells ...
- Nordic Collegiate Programming Contest 2015 G. Goblin Garden Guards
In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...
- Nordic Collegiate Programming Contest 2015 E. Entertainment Box
Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...
- Nordic Collegiate Programming Contest 2015 D. Disastrous Downtime
You're investigating what happened when one of your computer systems recently broke down. So far you ...
- (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...
- Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))
2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举
2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举 ...
随机推荐
- python多线程网络编程
背景 使用过flask框架后,我对request这个全局实例非常感兴趣.它在客户端发起请求后会保存着所有的客户端数据,例如用户上传的表单或者文件等.那么在很多客户端发起请求时,服务器是怎么去区分不同的 ...
- 大型网站系统与Java中间件实践
大型网站系统与Java中间件实践(贯通分布式高并发高数据高访问量网站架构与实现之权威著作,九大一线互联网公司CTO联合推荐) 曾宪杰 著 ISBN 978-7-121-22761-5 2014年4 ...
- Java项目——模拟电话薄联系人增删改查
该项目模拟了电话本记录联系人的业务功能,用来练习对数据库的增删改查等操作. 菜单类:Menu -- 用来封装主菜单和个选项的子菜单 Person类: Person--联系人的实体类 TelNoteRe ...
- Android 神兵利器—— Git 常用命令
总结的Android 工具类文章: Android 神兵利器-- Adb 常用命令 Android 神兵利器-- Git 常用命令 在项目研发时,经常使用Git,基本的命令有六个,通过下面的图片我们可 ...
- 每天一个linux命令(50):crontab命令
前一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个 ...
- apache2添加模块和添加站点
apache2添加模块和添加站点 linux下的apache2的目录和windows上的区别还是很大的,但是用起来却更方便了,详解请看另一篇文章http://www.cnblogs.com/wancy ...
- JS生成1000个数字加字母的不重复的随机字符串
周五,快下班了,正收拾东西准备走人,项目经理突然让我给他做个Excel,1000个数字加字母组合的密码,不重复,下班前给. 我直接懵了,Excel不会,估计是要写个什么命令才能生成出来,于是想着有没有 ...
- 【总结】探索Newlife组件:服务代理利器XAgent的前世今生
本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html Newlife XCode组件相关文章目录:http://www.cn ...
- 《BI那点儿事》Microsoft 神经网络算法
Microsoft神经网络是迄今为止最强大.最复杂的算法.要想知道它有多复杂,请看SQL Server联机丛书对该算法的说明:“这个算法通过建立多层感知神经元网络,建立分类和回归挖掘模型.与Micro ...
- [UWP]涨姿势UWP源码——Unit Test
之前我们讨论了涨姿势UWP的RSS数据源获取,以及作为文件存储到本地,再将数据转化成Model对象.这部分非UI的内容非常适合添加Unit Test.不涉及UI的话,UT写起来简单高效,很是值得投入一 ...