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 -二分+最短路+枚举 ...
随机推荐
- Spring 顾问
1.名称匹配方法切入点顾问 接口:ISomeService public interface ISomeService { public void doSome(); public void doSe ...
- webpack相关插件
webpack-merge:开发环境和生产环节的webpaak配置文件的配置合并 file-loader:编译写入文件,默认情况下生成文件的文件名是文件名与MD5哈希值的组合 vue-laoder:编 ...
- Generator 和 函数异步应用 笔记
Generator > ES6 提供的一种异步编程解决方案 > Generator 函数是一个状态机,封装了多个内部状态.还是一个遍历器对象生成函数.返回<label>遍历器对 ...
- canvas、svg、canvas与svg的区别
一.canvas canvas 画布,位图 <canvas> 标签定义图形,比如图表和其他图像,您必须使用脚本来绘制图形 注意:不要在style中给canvas设置宽高,会有位移差 can ...
- Linux 网卡驱动的安装
一.网卡驱动安装的一般思路 1.首先从硬 件安装,检查网卡本身故障 2.检查网卡芯片型号(注意不是硬件品牌) 常见的网卡芯片有Intel RC82545EM/Realtek 8139D/ Broadc ...
- SQL Server 2012安装配置(Part3 )
SQL Server 2012安装配置(Part1 ) SQL Server 2012安装配置(Part2 ) SQL Server 2012安装配置(Part3 ) 3 客户端安装 3.1 安装客户 ...
- linux系统及服务安全(持续更新中)
linux安全 1.隐藏NGINX和PHP版本号 curl -I "http://www.xxx.com" //检测 nginx: http段加入server_tokens of ...
- python基础教程总结9——模块,包,标准库
1. 模块 在python中一个文件可以被看成一个独立模块,而包对应着文件夹,模块把python代码分成一些有组织的代码段,通过导入的方式实现代码重用. 1.1 模块搜索路径 导入模块时,是按照sys ...
- UVA 1616 Caravan Robbers 商队抢劫者(二分)
x越大越难满足条件,二分,每次贪心的选区间判断是否合法.此题精度要求很高需要用long double,结果要输出分数,那么就枚举一下分母,然后求出分子,在判断一下和原来的数的误差. #include& ...
- mysql 速度检索
授权GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'127.0.0.1' IDENTIFIED BY 'zabbixpwd' WITH GRANT OPTI ...