标签:
8
186 186 150 200 160 130 197 220
4
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 //#include<bits/stdc++.h> 8 #include<iostream> 9 #include<cstring> 10 #include<cstdio> 11 #include<map> 12 #include<algorithm> 13 #include<queue> 14 #include<cmath> 15 #define ll __int64 16 #define PI acos(-1.0) 17 #define mod 1000000007 18 using namespace std; 19 int n; 20 int a[105]; 21 int l[105],r[105]; 22 int main() 23 { 24 scanf("%d",&n); 25 for(int i=1;i<=n;i++) 26 scanf("%d",&a[i]); 27 int ans[105]; 28 int exm=0; 29 ans[0]=0; 30 for(int i=1;i<=n;i++) 31 { 32 if(a[i]>ans[exm]) 33 { 34 exm++; 35 ans[exm]=a[i]; 36 l[i]=exm; 37 } 38 else 39 { 40 int pos=lower_bound(ans+1,ans+exm,a[i])-ans; 41 ans[pos]=a[i]; 42 l[i]=pos; 43 } 44 } 45 exm=0; 46 ans[0]=0; 47 for(int i=n;i>=1;i--) 48 { 49 if(a[i]>ans[exm]) 50 { 51 exm++; 52 ans[exm]=a[i]; 53 r[i]=exm; 54 } 55 else 56 { 57 int pos=lower_bound(ans+1,ans+exm,a[i])-ans; 58 ans[pos]=a[i]; 59 r[i]=pos; 60 } 61 } 62 int minx=200; 63 for(int i=1;i<=n;i++) 64 minx=min(minx,n-(l[i]+r[i]-1)); 65 printf("%d\n",minx); 66 return 0; 67 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5736602.html