zoukankan      html  css  js  c++  java
  • codeforces 98 div2 C.History 水题

    C. History
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.

    Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year biinclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event jincludes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.

    Input

    The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all ij (where i ≠ j). Events are given in arbitrary order.

    Output

    Print the only integer — the answer to the problem.

    Examples
    input
    5
    1 10
    2 9
    3 8
    4 7
    5 6
    output
    4
    input
    5
    1 100
    2 50
    51 99
    52 98
    10 60
    output
    4
    input
    1
    1 1000000000
    output
    0
    题意:给你n歌时间段,开始和结束,找出有多少个时间段在另外任意的时间段内;
    思路:所以我们先按结束时间排序,每次更新最小值;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define inf 100000000000005
    #define MAXN 10000010
    //#pragma comment(linker, "/STACK:102400000,102400000")
    struct is
    {
        int st,en;
        bool operator <(const is &x)const
        {
            if(en!=x.en)
            return en>x.en;
            return st<x.st;
        }
     }a[100010];
    int main()
    {
        int x,y,z,i,t;
        scanf("%d",&x);
        for(i=0;i<x;i++)
        scanf("%d%d",&a[i].st,&a[i].en);
        sort(a,a+x);
        int minn=a[0].st,maxx=a[0].en;
        int minnn=a[0].st,maxxx=a[0].en;
        int ans=0;
        for(i=1;i<x;i++)
        {
            if((maxx>a[i].en&&minn<a[i].st)||(maxxx>a[i].en&&minnn<a[i].st))
            ans++;
            if(a[i].st<minnn)
            {
                maxx=maxxx;
                minn=minnn;
                minnn=a[i].st;
                maxxx=a[i].en;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    ASP.NET MVC学习之模型绑定(2)
    ASP.NET MVC学习之模型绑定(1)
    ASP.NET MVC学习之模型模板篇
    ASP.NET MVC学习之视图篇(2)
    ASP.NET MVC学习之视图篇(1)
    C++迭代器的使用和操作总结
    C++ 11 线程调用类的成员函数解决办法
    详解 C++11 lambda表达式
    C++11 学习笔记 std::function和bind绑定器
    C++11中的std::bind
  • 原文地址:https://www.cnblogs.com/jhz033/p/5509953.html
Copyright © 2011-2022 走看看