zoukankan      html  css  js  c++  java
  • 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, k(1 le k < n le 100 000)(1k<n100000). 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 0000xi<yi1000000000.

    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​

     

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <vector>
     5 #include <string>
     6 #include <string>
     7 #include <map>
     8 #include <cmath>
     9 #include <set>
    10 #include <algorithm>
    11 using namespace std;
    12 const int N=1e5+9;
    13 struct Node
    14 {
    15     int s,e;
    16 }node[N];
    17 bool cmp(Node a,Node b)
    18 {
    19     return a.e<b.e;//按终止时间从小到大
    20 }
    21 int n,k;
    22 multiset<int>se;//可以存储等值元素
    23 /*
    24 1 8
    25 2 9
    26 5 10
    27 7 10    
    28 _____
    29 就会有10 10 (k==2)
    30 */
    31 multiset<int>::iterator it;//注意::写在前面
    32 int  main()
    33 {
    34     scanf("%d%d",&n,&k);
    35     for(int i=0;i<n;i++ ) scanf("%d%d",&node[i].s,&node[i].e);
    36     sort(node,node+n,cmp);
    37     se.clear();
    38     for(int i=0;i<k;i++)  se.insert(0);
    39     int ans=0;
    40     for(int i=0;i<n;i++)
    41     {
    42         it=se.upper_bound(node[i].s);
    43         if(it==se.begin())  continue;
    44         it--;//第一个>node[i].s的数的前面的数一定是小于node[i].sb_type
    45              // 并且一定是和node[i].s的差值最小的(贪心),把更早结束的留给开始时间比较小的
    46         se.erase(it);//播放完了,就要更新掉/
    47         se.insert(node[i].e);
    48         ans++;
    49     }
    50     printf("%d
    ",ans);
    51     return 0;
    52 }
  • 相关阅读:
    Go module学习笔记
    java并发基础及原理
    java并发之内存模型
    https理论及实践
    Mysql查询结果导出Excel表
    mysql清空表数据并重置自增ID
    html a标签链接点击闪动问题解决
    rocketmq-console控制台管理界面配置
    nginx多层反代配置变量proxy_set_header
    nginx 实现浏览器文件下载服务
  • 原文地址:https://www.cnblogs.com/tingtin/p/9382822.html
Copyright © 2011-2022 走看看