2017.10.6北京清北综合强化班DAY6

 2017.10.6北京清北综合强化班DAY6

 

题目大意:改变一个数的位置 把一个序列变成不下降序列

题解:

设置一个pre,如果破坏单调性,就把‘删除’这个。否则把pre修改为当前元素的值。

考试时这样得了90分,是因为我的做法只能过这样的数据

1 3 4 1 5 7  (这个序列移动的数字是第二个1)

不能过这样的

1 3 6 100 7 9 10 (这个序列按我的做法移动的是7,但是应该是移去100)

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000009
using namespace std;

int n,pre,tot,a[maxn];

inline int read(){
    char ch=getchar();int x=0,f=1;
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
    return x*f;
}

int main(){
    freopen("sort.in","r",stdin);
    freopen("sort.out","w",stdout);
    n=read();pre=read();
    for(int i=2;i<=n;i++){
        a[i]=read();
        if(a[i]<pre){
            tot++;
            if(tot>1){
                printf("NO\n");
                return 0;
            }
        }
        else pre=a[i];
    }
    printf("YES\n");
    fclose(stdin);fclose(stdout);
    return 0;
}
90

相关文章: