B.Sort the Array
B.排序数组
time limit per test: 1 second
每次测试的时间限制:1秒
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
Being a programmer,you like arrays a lot.For your bithday,your friends have given you an array a consisting of n distinct integers.
作为一名程序员,你非常喜欢数组。在你的双日里,你的朋友给你一个数组a,它由n个不同的整数组成。
Unfortunately, the size of a is too small You want a bigger arayl Your frinds agree to give you a bigger aray, but only if you are able to
不幸的是,a的大小太小了–你想要一个更大的数组–你的兄弟会同意给你一个更大的数组,但前提是你能够
answer the following question correcty. is it possible to sort the array a (in increasing order) by reversing exactly one segment of d? Se
正确回答以下问题。是否可以通过完全反转一个d段来对数组a进行排序(按增加的顺序)?硒
definitions of segment and reversing in the notes.
注释中分段和反转的定义。
lnput
输入
The first line of the input contains an integer n(1≤ns10)-the size of array a.
输入的第一行包含整数n(1≤ns 10)–数组a的大小。
The second line contains n distinct space-separated integers: a[1].a[2]…awi.
第二行包含n个不同的空分隔整数:a[1].a[2].awi。
output
输出量
Print"yes" or “no” (without quotes),depending on the answer.
根据答案打印“是”或“否”(没有引号)。
lf your answer is “yes” , then also print two space-separated integers denoting start and end (start must not be greater than end) indices of
如果您的回答是“是”,则还打印两个空格分隔的整数,表示开始和结束(开始不得大于结束)索引。
the segment to be reversed. lf there are multiple ways of selecting these indices,print any of them.
部分将被反转。如果有多种选择这些索引的方法,请打印其中任何一个。
数单减次数
int main()
{
int n,un,th,t=0,x,y;
cin >> n>>un;
for (int i = 2; i <= n;)
{
cin >> th;
++i;
if (th < un)
{
x = i-2;
++t;
while (th < un&&i<=n)
{
un = th;
cin >> th;
++i;
}
y = i-1;
}
un = th;
}
if (t >1)
cout << "no" << endl;
else if (!t)
cout << "yes\n1 1" << endl;
else
cout << "yes" << endl << x << ' ' << y << endl;
return 0;
}