AC日记——Little Elephant and Problem codeforces 221c

221C

 

思路:

  水题;

 

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define maxn 200005

int n,ai[maxn],bi[maxn],ans;

inline void in(int &now)
{
    int if_z=1;now=0;
    char Cget=getchar();
    while(Cget>'9'||Cget<'0')
    {
        if(Cget=='-') if_z=-1;
        Cget=getchar();
    }
    while(Cget>='0'&&Cget<='9')
    {
        now=now*10+Cget-'0';
        Cget=getchar();
    }
    now*=if_z;
}

bool cmp(int a,int b)
{
    return a<b;
}

int main()
{
    in(n);
    for(int i=1;i<=n;i++) in(ai[i]),bi[i]=ai[i];
    sort(ai+1,ai+n+1,cmp);
    for(int i=1;i<=n;i++) if(ai[i]!=bi[i]) ans++;
    if(ans<=2) cout<<"YES";
    else cout<<"NO";
    return 0;
}

 

posted @ 2017-05-10 22:31  IIIIIIIIIU  阅读(185)  评论(0编辑  收藏  举报