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;
}

 

转载于:https://www.cnblogs.com/jhz033/p/5509953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值