451B - Sort the Array
2014-08-17 23:18
441 查看
这道题的意识是给你一个整形数组,含有很多数字,然后让你通过讲中间的某一个字串颠倒过来,让他成为不下降的数组。其实这题都是特简单的,只要你找到一个不满足上升的字串,然后反过来,直接break,最后判断是不是非下降排列即可。
#include<iostream> using namespace std; #include<cstring> #include<stdio.h> int a[100005]; int main() { int N; int i,j,k; while(cin>>N) { k=0;//标记 int i1=0,j1=0; for(i=0;i<N;i++) scanf("%d",&a[i]); for(i=0;i<N-1;i++) { if(a[i]>a[i+1]) { if(!k) { k=1; i1=i; } } else if(k) { j1=i; break; } } if(k&&j1==0)j1=N-1; // cout<<i1<<" "<<j1<<endl; k=j1; for(i=i1;i<=(j1+i1)/2;i++,k--) { j=a[i]; a[i]=a[k]; a[k]=j; } k=0; for(i=0;i<N-1;i++) if(a[i]>a[i+1]) { k=1; break; } // for(i=0;i<N;i++) // cout<<a[i]<<" "; if(k)cout<<"no"<<endl; else { cout<<"yes"<<endl; cout<<(i1+1)<<" "<<(j1+1)<<endl; } } return 0; }
相关文章推荐
- 451 B. Sort the Array
- B - Sort the Array
- .sortEntities()is called this array is sorted by the entities.zIndex.
- Find the median of 2 sort ed array.
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
- B - Sort the Array
- Codeforces Div. 2 #258-B. Sort the Array
- GeeksforGeeks Sort an array according to the order defined by another array
- Sort the Array CodeForces - 451B
- Ruby: how to sort array of string parsing the content
- Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)
- How do I sort an array of hashes by a value in the hash?
- B题 Sort the Array
- Codeforces Round #258 (Div. 2)——B. Sort the Array(STL-reverse)
- [Codeforces 451B] Sort the Array (实现)
- How do I sort an array of hashes by a value in the hash?
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
- codeforce-B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
- Sort the Array (CF)