| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
O(N)//left记录i左边2的个数
//right记录i右边1的个数
//好吧,我这个是用枚举改的
#include<iostream>
using namespace std;
int arr[30010];
int N;
int main(){
scanf("%d",&N);
int t=0;
for(int i=0;i<N;i++){
scanf("%d",&arr[i]);
if(arr[i]==1)
t++;
}
int left,right;
if(arr[0]==2){
left=1;
right=t;
}
else{
left=0;
right=t-1;
}
int cnt=0;
int min=left+right;
for(int i=1;i<N;i++){
if(arr[i]==1)
right--;
else
left++;
if(left+right<min)
min=left+right;
}
min=min<t?min:t;
min=min<N-t?min:N-t;
printf("%d\n",min);
system("PAUSE");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator