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 -二分+最短路+枚举 ...
随机推荐
- Django使用网站图标
默认情况下,浏览器访问一个网站的时候,同时还会向服务器请求“/favicon.ico”这个URL,目的是获取网站的图标. 若是没有配置的话,Django就会返回一个404错误,并且浏览器接收到这个40 ...
- 洛谷P1781 宇宙总统
https://www.luogu.org/problem/show?pid=1781 高精比较大小: #include<iostream> #include<cstdio> ...
- springboot 学习笔记(二)
springboot 学习笔记(二) 快速创建一个springboot工程,并引入所需要的依赖 1.利用Spring initializr 来创建一个springboot项目,登陆http://sta ...
- My1stServlet
Servlet可以看做是一个嵌套了Html代码的Java类: 1.首先创建一个Servlet类,例子如下 import java.io.PrintWriter; import javax.servle ...
- android动画ppt整理
案例
- Azure 虚拟机安全加固整理
这篇文档不是原创,只是基于Azure官网上的Doc进行了相关链接的整理,从简单层面的安全设置,到更高层面的安全架构考量,以及Azure安全的白皮书及最佳实践,送给需要的你们,定有一款适合你! 做好数据 ...
- 日常-acm-开灯问题
开灯问题.有n盏灯,编号1-n.第一个人把所有的灯打开,第二个人按下所有编号为二的倍数的开关(全关掉),第三个人按下所有编号为三的倍数的开关,以此类推.一共k个人,问最后开着的灯的编号.输入n和k,输 ...
- HDU 5459 Jesus Is Here (递推,组合数学)
有点麻烦的递推,递推的原则:向小的问题方向分解,注意边界. 字符串的递推式为 定义f为Si中的总方案数 首先可以得到 fi=fi-1+fi-2+组合(si-2,si-1) 然后考虑Si-2和Si-1之 ...
- 关于 NetBackup 应答文件(/tmp/NBInstallAnswer.conf)
关于 NetBackup 应答文件 在 UNIX 和 Linux 安装和升级期间使用 NetBackup 应答文件 (/tmp/NBInstallAnswer.conf),以便: 覆盖某些默认值. 避 ...
- APT和它的超级牛力
当你在使用apt时,例如“apt -h”会提示“本APT具有超级牛” 先把牛放一放,先学习以下关于APT的知识. APT 高级打包工具(英语:Advanced Packaging Tools,缩写为A ...