zoukankan      html  css  js  c++  java
  • Scientific Conference

    Scientific Conference

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    Functioning of a scientific conference is usually divided into several simultaneous sections. For example, there may be a section on parallel computing, a section on visualization, a section on data compression, and so on.
    Obviously, simultaneous work of several sections is necessary in order to reduce the time for scientific program of the conference and to have more time for the banquet, tea-drinking, and informal discussions. However, it is possible that interesting reports are given simultaneously at different sections.
    A participant has written out the time-table of all the reports which are interesting for him. He asks you to determine the maximal number of reports he will be able to attend.

    Input

    The first line contains the number 1 ≤ N ≤ 100000 of interesting reports. Each of the next N lines contains two integers Ts and Teseparated with a space (1 ≤ Ts < Te ≤ 30000). These numbers are the times a corresponding report starts and ends. Time is measured in minutes from the beginning of the conference.

    Output

    You should output the maximal number of reports which the participant can attend. The participant can attend no two reports simultaneously and any two reports he attends must be separated by at least one minute. For example, if a report ends at 15, the next report which can be attended must begin at 16 or later.

    Sample Input

    inputoutput
    5
    3 4
    1 5
    6 7
    4 5
    1 3
    
    3

    贪心:

        结束的越早越是优;

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    const int maxn = 1e5+5;
    using namespace std;
    struct node{
        int s, t;
        bool operator < (const node &x)const{
            return t < x.t;
        }
    }a[maxn];
    int main(){
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++){
            scanf("%d%d", &a[i].s, &a[i].t);
        }
        sort(a, a+n);
        int ans = 0;
        int tmp = 0;
        for(int i = 0; i < n; i++){
            if(a[i].s > tmp){
                tmp = a[i].t;
                ans++;
            }
        }
        printf("%d
    ", ans);
        return 0;
    }
     
  • 相关阅读:
    HDU 3911 Black And White 分段树 题解
    Haskell 差点儿无痛苦上手指南
    CFileDialog的使用方法简单介绍
    对 dpif_class 结构体的一点认识
    三层架构之基础知识
    五类常见算法小记 (递归与分治,动态规划,贪心,回溯,分支界限法)
    AlertDialog具体解释
    delphi tcp/ip IdTCPServer1实例一
    23种设计模式(15):备忘录模式
    Android APK反编译具体解释(附图)
  • 原文地址:https://www.cnblogs.com/ACMessi/p/4900651.html
Copyright © 2011-2022 走看看