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 }
  • 相关阅读:
    因素的随机选择,这里只是处理了 20 % 也是80 %
    随机函数完成。就是要的这个效果。
    poly 奇数偶数 隔点选择。 实时的 线 面的选择, 就是和max2011 石墨一样的办法,我只是没有用when 。
    在 poly中根据线段的长短,还有就是面积的选择
    终于找到bit 的资料了,我是poly 中看到的。
    常用脚本资料词汇
    转:Android源码分析
    Android内核的简单分析(转
    转:Android核心模块及相关技术介绍
    Google Earth 的几个标志性地方。
  • 原文地址:https://www.cnblogs.com/tingtin/p/9382822.html
Copyright © 2011-2022 走看看