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 -二分+最短路+枚举 ...
随机推荐
- vue for 绑定事件
vue for 绑定事件 <div id="pro_list" v-for="item in pro_list"> <div class=&q ...
- Struts2学习笔记 - Action篇<配置文件中使用通配符>
有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这里就说一下在配置文件中使用通配符,这里的关键就是struts.xml配置文件,在最简单的 ...
- SharePoint 2013连接非默认端口的SQL Server
SharePoint 2013场在连接的时候不允许出现连接地址中包含端口号,否则场配置就会报错,在执行到配置场数据库时无法完成. 此时如果SQL Server不是用的默认端口1433的 ...
- 【WP 8.1开发】解决调用真实摄像头会死机的问题
无论你是用Silverlight还是用RT的API来开发,在使用MediaCapture拍照片或录视频时,要是在模拟器上运行会万事大吉:但是,一旦放到真实手机上运行,肯定有人发现了,细心的朋友肯定发现 ...
- 使用supervisor提高nodejs调试效率
如果你有PHP 开发经验,会习惯在修改PHP 脚本后直接刷新浏览器以观察结果,而你 在开发Node.js 实现的HTTP 应用时会发现,无论你修改了代码的哪一部份,都必须终止 Node.js 再重新运 ...
- Android内存回收机制
退出但不关闭: 这是Android对于Linux的优化.当 Android 应用程序退出时,并不清理其所占用的内存,Linux 内核进程也相应的继续存在,所谓“退出但不关闭”.从而使得用户调用程序时能 ...
- OpenCascade Tcl vs. ACIS Scheme
OpenCascade Tcl vs. ACIS Scheme eryar@163.com 摘要Abstract:本文通过OpenCascade的Tcl/Tk和ACIS的Scheme的对比来说明脚本语 ...
- struts2简单数据验证
当表单数据提交到后台后通常要对数据进行校验,以登录为例,后台拿到用户名密码后会判断是否正确,正确的话会跳转到网站用户登录成功的页面,如果不正确的话会提示用户输入不正确. 首先在struts.xml配置 ...
- ObjectOutputStream和ObjectInputStream
官方解释: ObjectOutputStream 将 Java 对象的基本数据类型和图形写入 OutputStream.可以使用 ObjectInputStream 读取(重构)对象.通过使用流中的文 ...
- 了解HTML表单之13个表单控件
目录 传统控件 button select option optgroup textarea fieldset legend label 新增控件 datalist keygen output pro ...