zoukankan      html  css  js  c++  java
  • 【Luogu3929】SAC E#1

    problem

    solution

    codes

    #include<cstdio>
    
    int n, a[(int)1e5+10];
    
    int readint(){
        int op=1,x=0; char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')op=-1; ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
        return op*x;
    }
    
    bool check(int dir){
        int cnt = 0;
        for(int i = 2; i <= n; i++, dir=!dir){ //到下一个数判断,方向需要改变
            if(a[i]==a[i-1])continue;  //值相同毫无存在感
            if((a[i]<a[i-1]) == dir)continue; //方向正确
            if(++cnt >= 2)return false;
            else i++,dir=!dir; //如果还没有炸,那么要跳过这个值再比较
        }
        return true;
    }
    
    int main(){
        while(scanf("%d",&n)==1){
            for(int i = 1; i <= n; i++)a[i]=readint();
            printf("%s
    ",n<=3||check(0)||check(1)?"Yes":"No");
        }
        return 0;
    }
  • 相关阅读:
    java
    MVC4重复提交数据
    cache
    Nosql
    MVC4重复提交
    PHP Java
    .net performance
    How the Runtime Locates Assemblies
    android
    window.onscroll
  • 原文地址:https://www.cnblogs.com/gwj1314/p/9444713.html
Copyright © 2011-2022 走看看