codeforces 258div2 B Sort the Array

时间:2023-12-13 17:37:44

题目链接:http://codeforces.com/contest/451/problem/B

解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列。

我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long INT;
const int maxn = +;
INT que[maxn],que2[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i <= n;++i)
{
scanf("%lld",&que[i]);
que2[i] = que[i];
}
sort(que+,que+n+);
int l = ;
for(;l < n;++l)
if(que[l] == que[l+])
break;
if(l < n)
{
printf("no\n");
continue;
}
int s = ,e = n;
while(s <= n && que[s] == que2[s]) s++;
if(s > n)
{
printf("yes\n1 1\n");
continue;
}
while(e >= && que[e] == que2[e]) e--;
int x = s,y = e;
while(s <= y && que[s] == que2[e]) s++,e--;
printf(s > y? "yes\n%d %d\n":"no\n",x,y);
}
return ;
}