Heim >Datenbank >MySQL-Tutorial >Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)

Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:00:581207Durchsuche

题目链接:Codeforces Round #258 (Div. 2) B. Sort the Array 题意:给出一串序列要就通过一次反转一段子序列使得变化后的序列严递增。 思路:从左向右找出首次下降的,从右向左找出首次下降的,分别记录下标,再在这个段区间里反转。最后判断是否递增。 反

题目链接:Codeforces Round #258 (Div. 2) B. Sort the Array

题意:给出一串序列要就通过一次反转一段子序列使得变化后的序列严格递增。

思路:从左向右找出首次下降的,从右向左找出首次下降的,分别记录下标,再在这个段区间里反转。最后判断是否递增。

反转想到字符串(或STL)有个反转库函数。读者可以试试。

AC代码:


#include<stdio.h>
int main()
{
	int n,i;
	int x,y,j;
	int a[100010];
	while(scanf("%d",&n)!=EOF)
	{
		for(i=1;i=a[i])
			{
				x=i-1;
				break;
			}
		}
		for(i=n;i>=1;i--)
		{
			if(a[i-1]>=a[i])
			{
				y=i;
				break;
			}
		}
		//一开始就是递增的
		int t;
		if(x==y && x==-1)
		{
			printf("yes\n%d %d\n",1,1);
			continue;
		}
		//反转。
		for(i=x,j=1;j=a[i])
			{
				mark=1;
				break;
			}
		}
		if(mark==1)
			printf("no\n");
		else
			printf("yes\n%d %d\n",x,y);
	}
return 0;
}</stdio.h>



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:JavaScript回顾(2)Nächster Artikel:springmvc中使用axis2中的一些问题