提交链接

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(有点变化的贪心)的更多相关文章

  1. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  2. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  3. 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 ...

  4. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  5. 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 ...

  6. 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 ...

  7. (寒假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 ...

  8. 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颗星,心态被打崩了,会的算法太少了,知 ...

  9. 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 -二分+最短路+枚举 ...

随机推荐

  1. 搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展

    上一篇:搭建LNAMP环境(四)- 源码安装PHP7 一.安装Redis 1.创建redis用户组和用户 groupadd redis useradd -r -g redis -s /sbin/nol ...

  2. [转]Java并发编程:Lock

    链接: http://www.cnblogs.com/dolphin0520/p/3923167.html

  3. 实用的开放源码的Excel导入导出类库 CarlosAg ExcelXmlWriter

    做企业管理软件经常会遇到要把数据导出成EXCEL格式,目前市面上有很多工具类库可以实现此功能.CarlosAg ExcelXmlWriter是其中之一,它绿色小巧,免安装,又源码开放,我在项目中一直以 ...

  4. JAVA EE Hibernate基础一之环境配置

    对于JAVA开发高级,hibernate是java三大框架之一,足以见得它的重要性,那么对于hibernate的使用大家有了解多少呢?从今天开始我将带领大家一道共同探讨一下hibernate的知识,h ...

  5. Android属性动画之第一重修炼总结

    经过这两天对ObjectAnimator属性动画的学习,基本对Android提供的属性动画有了一定的认识,现在就为大家以一个类似扇形打开的效果做总结. 效果图: 下面就让我们用刚刚学到的属性动画效果, ...

  6. 【原创】Newlife.XCode的常见功能使用(一)查询与数据初始化

            本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html Newlife XCode组件相关文章目录:http://www ...

  7. python--基础学习(六)sqlite数据库基本操作

    python系列均基于python3.4环境 1.新建数据表 新建表,命名为student(id, name, score, sex, age),id为关键字,代码如下: import sqlite3 ...

  8. 解决firefox和IE9对icon font字体的跨域访问问题

    何为跨域访问,为什么会有跨域限制?一切还得从浏览器的同源策略说起. 同源策略:是浏览器最核心也是最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能会受到影响,可以说Web是构建在同源策略基础 ...

  9. 编写可编辑的List控件

    今天由于项目的需要,要编写个能编辑的List控件,即双击List控件的表项能修改其中的内容.由于MFC自带的List控件是不能编辑的,所以在网上找了下怎样编写可编辑的CListCtrl控件,基本上都是 ...

  10. 应用在tomcat下的四种部署方式(原创)

    1.XML主动部署 2.XML自动部署 3.WAR自动部署 4.DIR自动部署 主动部署就是在server中配置部署,自动部署不需要在server中部署. 自动部署要比主动部署多一些功能,例如监测特定 ...