451 B. Sort the Array
2014-07-25 23:56
405 查看
/* 直接模拟判断即可,也可以排序进行判断 注意边界情况 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[100100]; int main() { int n; scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d",&a[i]); int flag=0; for(int i=1;i<n;i++) { if(a[i]<a[i-1]) { flag=1; break; } } if(!flag) { printf("yes\n1 1\n"); return 0; } int cnt=0; for(int i=1;i+1<n;++i) { if(a[i-1]>a[i]&&a[i]<a[i+1]) cnt++; } if(a[n-2]>a[n-1]&&n>1) cnt++; if(cnt>1) { printf("no\n"); return 0; } int loc1,loc2; loc1=loc2=0; for(int i=0;i<n;++i) { if(a[i]>a[i+1]) { loc1=i; for(int j=i+1;j<n;++j) { if(a[j]<a[j-1]) { loc2=j; } else { break; } } break; } } if(loc2+1<n&&a[loc1]>a[loc2+1]) { printf("no\n"); return 0; } if(loc1>0&&a[loc2]<a[loc1-1]) { printf("no\n"); return 0; } printf("yes\n%d %d\n",loc1+1,loc2+1); return 0; }
相关文章推荐
- 451B - Sort the Array
- 【寒江雪】B.Sort the array
- Sort an array alphabetically in Ruby but with capitalised words at the end
- B - Sort the Array
- .sortEntities()is called this array is sorted by the entities.zIndex.
- Find the median of 2 sort ed array.
- GeeksforGeeks Sort an array according to the order defined by another array
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
- B - Sort the Array
- Codeforces Div. 2 #258-B. Sort the Array
- Ruby: how to sort array of string parsing the content
- Sort the Array CodeForces - 451B
- How do I sort an array of hashes by a value in the hash?
- Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)
- B题 Sort the Array
- Codeforces Round #258 (Div. 2)——B. Sort the Array(STL-reverse)
- How do I sort an array of hashes by a value in the hash?
- [Codeforces 451B] Sort the Array (实现)
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
- codeforce-B. Sort the Array