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 fights they have finally decided to buy a video tape recorder. This fabulous, new device can record kk different TV shows simultaneously, and whenever a show recorded in one the machine's kk 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 Format
The first line of input contains two integers nn, kk (1 \le k < n \le 100 000)(1≤k<n≤100000). Then follow nn lines, each containing two integers x_i, y_ixi,yi, meaning that show ii starts at time x_ixi and finishes by time y_iyi. This means that two shows iiand jj, where y_i = x_jyi=xj, can be recorded, without conflict, in the same recording slot. You may assume that 0 \le x_i < y_i \le 1 000 000 0000≤xi<yi≤1000000000.
Output Format
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.
样例输入1
3 1
1 2
2 3
2 3
样例输出1
2
样例输入2
4 1
1 3
4 6
7 8
2 5
样例输出2
3
样例输入3
5 2
1 4
5 9
2 7
3 8
6 10
样例输出3
3
题目来源
Nordic Collegiate Programming Contest 2015
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <string>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
const int N=1e5+;
struct Node
{
int s,e;
}node[N];
bool cmp(Node a,Node b)
{
return a.e<b.e;//按终止时间从小到大
}
int n,k;
multiset<int>se;//可以存储等值元素
/*
1 8
2 9
5 10
7 10
_____
就会有10 10 (k==2)
*/
multiset<int>::iterator it;//注意::写在前面
int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++ ) scanf("%d%d",&node[i].s,&node[i].e);
sort(node,node+n,cmp);
se.clear();
for(int i=;i<k;i++) se.insert();
int ans=;
for(int i=;i<n;i++)
{
it=se.upper_bound(node[i].s);
if(it==se.begin()) continue;
it--;//第一个>node[i].s的数的前面的数一定是小于node[i].sb_type
// 并且一定是和node[i].s的差值最小的(贪心),把更早结束的留给开始时间比较小的
se.erase(it);//播放完了,就要更新掉/
se.insert(node[i].e);
ans++;
}
printf("%d\n",ans);
return ;
}
Nordic Collegiate Programming Contest 2015 E. Entertainment Box的更多相关文章
- 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 ...
- 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 D. Disastrous Downtime
You're investigating what happened when one of your computer systems recently broke down. So far you ...
- Nordic Collegiate Programming Contest 2015(第七场)
A:Adjoin the Networks One day your boss explains to you that he has a bunch of computer networks tha ...
- (寒假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 ...
- German Collegiate Programming Contest 2015 计蒜课
// Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...
- 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 -二分+最短路+枚举 ...
随机推荐
- Zeppelin的入门使用系列之使用Zeppelin来创建临时表UserTable(三)
不多说,直接上干货! 前期博客 Zeppelin的入门使用系列之使用Zeppelin运行shell命令(二) 我们必须要先使用Spark 语句创建临时表UserTable,后续才能使用Spark SQ ...
- Linux开机启动服务
一.添加启动脚本 vim /etc/rc.d/rc.local sh /home/glt/apache-tomcat-/bin/email.sh 二.启动服务 systemctl enable rc- ...
- C#oracle还原imp实例
C#来做oracle还原,调用oracle自带函数imp.exe时,需要注意的是:1.imp.exe 中fromuser 和touser两个关键字: fromuser与exp.exe中的owner对应 ...
- sql常用操作(一)
sql(structured query language,结构化查询语言)语言:和数据库交互的语言,进行数据库管理的语言. 1.1 sql语句的作用:说白了就是增删改查 管理数据库 管理表 管理数据 ...
- 传入泛型类型(T.class)的方法
java中当我们需要T.class时会报错,这是我们只需定义一个Class<T>类作为参数传入即可,具体如下: public List<T> findStuByQuery(De ...
- 终于有人把P2P、P2C、O2O、B2C、B2B、C2C的区别讲透了!还有许多其它类别的类型分享
平时在看招聘时,经常看到我们是什么B2C电子商务网站,但是一直不知是啥意思,今天在WEB开发者上面看到这篇文章,就是知道了个所以然,以记录分享. P2P.P2C .O2O .B2C.B2B. C2C, ...
- SQL数据库基础二
- Image(支持 XML 序列化),注意C#中原生的Image类是无法进行Xml序列化的
/// <summary> /// Image(支持 XML 序列化) /// </summary> [XmlRoot("XmlImage")] publi ...
- JavaScript 的 parseInt 取整
http://www.neoease.com/javascript-get-integer-via-parseint/ JavaScript 是弱类型语言, 为了保证数值的有效性, 在处理数值的时候, ...
- 【vue iview】项目 win10 放在C盘 经常npm install不成功,就是因为 权限问题,把代码目录放到D盘就没事了。
[vue iview]项目 win10 放在C盘 经常npm install不成功,就是因为 权限问题,把代码目录放到D盘就没事了.