2017 9 15 noip模拟赛

t1:

#include<cstdio>
#include<cstring>
const int N=1000010;
int a[N],b[N];
int sum=1,maxx=0;
int main()
{
    freopen("sequence.in","r",stdin);
    freopen("sequence.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]);
    int now=1,last=1,t=a[1];
    while(now<n)
    {
        now++,sum++;
        if(b[now]<t)
        {
            last++;now=last;t=a[now];sum=1;
        }
        else if(t<a[now]) 
        {
            t=a[now];last=now;
        }
        if(maxx<sum) maxx=sum;
    }
    printf("%d",maxx);
    return 0;
}
View Code

贪心,注意初值;

posted @ 2017-09-16 13:55  12fs  阅读(112)  评论(0编辑  收藏  举报