Sort the Array

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值