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

 

相关文章:

  • 2022-02-24
  • 2021-07-21
  • 2021-07-13
  • 2021-11-08
  • 2022-01-28
  • 2021-10-14
  • 2021-09-19
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2022-03-07
  • 2021-08-22
  • 2022-02-21
  • 2021-08-27
  • 2021-07-08
  • 2021-05-29
相关资源
相似解决方案