Smallest Sub Array-hihocoder-tiger
来源:互联网 发布:淘宝上的香皂花有毒吗 编辑:程序博客网 时间:2024/05/10 17:33
述样例输入 样例输出 4
Given an array of integers A, find the smallest contiguous sub array B of A such that when you sort B in ascending order the whole array A becomes sorted as well.
For example if A = [1, 2, 3, 7, 4, 6, 5, 8] the smallest B will be [7, 4, 6, 5].
输入
The first line contains an integer N denoting the length of A. (1 <= N <= 100000)
The second line contains N integers denoting the array A. (0 <= Ai <= 100000000)
输出
The length of the smalltest sub array B.
8 1 2 3 7 4 6 5 8
#include <bits/stdc++.h>using namespace std;const int MAXN = 100010;int chary[MAXN];int main(){ freopen("in.txt", "r", stdin); int n, beg, endd; beg = endd = 0; int ans = 0; cin>>n; for( int i=0 ; i<n ; i++ ) cin>>chary[i]; int i,j; for( i=0 ; i<n-2 ; i++ ) { if( chary[i] > chary[i+1] ) { beg = i; break; } } for( i=n-2 ; i>=beg ; i-- ) { if( chary[i] > chary[i+1] ) { endd = i; break; } } sort( chary+beg, chary+endd+1 ); int tmpmax = chary[endd]; j = endd; for( i=n-1 ; i>= j ; i-- ) { if( chary[i] < tmpmax ) { endd = i; break; } } ans = beg!=endd ? endd - beg + 1 : 0 ; cout<<ans<<endl; return 0;}
0 0
- Smallest Sub Array-hihocoder-tiger
- 11536 - Smallest Sub-Array
- Smallest Sub-Array UVA
- UVA 11536 - Smallest Sub-Array
- UVa 11536 - Smallest Sub-Array
- UVa 11536 Smallest Sub-Array
- Uva - 11536 - Smallest Sub-Array
- uva 11536Smallest Sub-Array
- UVA 11536 Smallest Sub-Array
- 11536 - Smallest Sub-Array (two pointer)
- uva 11536 - Smallest Sub-Array(Towpointer)
- UVA - 11536 Smallest Sub-Array 纪录
- UVA:11536 Smallest Sub-Array(尺取法)
- 11536 - Smallest Sub-Array(滑动窗口)
- uva 11536——Smallest Sub-Array
- UVA 11536(p255)----Smallest Sub-Array
- UVA - 11536 Smallest Sub-Array (滑动窗口)
- UVA11536:Smallest Sub-Array(最短子序列)
- 【HDU】5958 New Signal Decomposition【离散对数下的FFT】
- android adb源码分析(1)
- Acitvity 进场动画 退出动画
- Android开发必备的一些常见Dos命令
- scss style guide
- Smallest Sub Array-hihocoder-tiger
- P,NP,NPC
- java编程思想读书笔记 第十八章 java I/O系统(第二篇)
- 基于【八股文】格式编写WordCount程序
- IntelliJ IDEA环境搭建
- Ubuntu12.04更改源的方
- SpringMVC框架是什么
- jQuery的deferred对象详解
- static修饰符