提交链接

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. struts2学习笔记之七:Result类型

    一:关于Struts2的type类型,也就是Result类型,他们都实现了共同的接口Result,都实现了execute方法 他们体现了策略模式,具体Result类型参见:struts-default ...

  2. salesforce 零基础学习(四十一)Group

    salesforce中,有的时候我们需要将一组用户放进一个Group,用来实现以下主要功能: 1.通过sharing rule设置默认的共享访问; 2.将记录分享给其他用户; 3.指定同步的联系人,这 ...

  3. JS 内置对象

    内置对象的定义:有ECMAScript实现提供的.不依赖与宿主环境的对象,在ECMAScript运行之前就已经创建好的对象就叫做内置对象. 就是说,是不需要我们开发人员先是的实例化对象就能够调用和运行 ...

  4. 阿里云部署Java web项目初体验(转)/linux 上配置jdk和安装tomcat

    摘要:本文主要讲了如何在阿里云上安装JDK.Tomcat以及其配置过程.最后以一个实例来演示在阿里云上部署Java web项目. 一.准备工作 购买了阿里云的云解析,和云服务器ecs. 2.下载put ...

  5. webpack配置详解

    webpack配置详解 先点个赞吧,再挨个点下面的连接,觉得不值这个赞的回来骂我啊. Webpack傻瓜式指南(一) Webpack傻瓜指南(二)开发和部署技巧 Webpack傻瓜式指南 原生的官网详 ...

  6. gulp学习笔记4

    gulp系列学习笔记: 1.gulp学习笔记1 2.gulp学习笔记2 3.gulp学习笔记3 4.gulp学习笔记4 之前的任务都是单个的,比较简单.接下去我们开始引用多个插件,一次性把任务搞定,省 ...

  7. Ubuntu14.04安装pip及配置

    安装pip: wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate sudo python get-pip.py 建立软连接 ...

  8. 快速入门系列--WCF--04元数据和异常处理

    本章节将进行元数据和异常处理的介绍,这部分内容概念型比较强,可以快速浏览一下就好. 客户端和服务器借助于终结点进行通信,服务的提供者通过一个或者多个终结点将服务发布出来,服务的消费者则通过创建与之匹配 ...

  9. Topology and Geometry in OpenCascade-Vertex

    Topology and Geometry in OpenCascade-Vertex eryar@163.com 摘要Abstract:本文简要介绍了几何造型中的边界表示法(BRep),并结合程序说 ...

  10. poj 3321 Apple Trie

    /* poj 3321 Apple Trie 这道题的关键是如何将一个树建成一个一维数组利用树状数组来解题! 可以利用dfs()来搞定,我们在对一个节点深搜后,所经过的节点的数目就是该节点的子树的数目 ...