题目
题意
有空再写
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector < int > a, b;
int j, n, temp,y=0,o;
long i = 0, x[2]={1,1};
bool k=true,l=true;
cin >> n;
for (j = 0; j < n; j++) {
cin >> temp;
a.push_back(temp);
b.push_back(temp);
}
sort(a.begin(), a.end());
for (j = 0; j < n; j++) {
if (a[j] != b[j]) {
i++;
x[y]=j+1;
if (k)
{
y++;
k=0;
}
}
}
for (j=x[0]-1,o=x[1]-1;j<x[1],o>=x[0]-1;j++,o--)
{
if (a[j]!=b[o])
l=0;
}
if (l) {
cout << "yes" << endl;
cout << x[0] << " " << x[1]<<endl;
}else cout << "no"<<endl;
return 0;
}
感受
1300分,基础题,从此题开始使用C++写题目,C++在很多方面优于C,许多特性很适合用来提高代码的效率,降低复杂度。
思路
有空再写。