Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

直接枚举

Posted by 631128 at 2008-08-16 19:13:32 on Problem 3671
#include<stdio.h>
#include<string.h>
#define MAX 100000000
int n,a[30010];
int b[30010];
int main()
{
	memset(b,0,30010*sizeof(int));
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==1)
			b[i]=b[i-1]+1;
		else b[i]=b[i-1];
	}
	if(b[n]==n||b[n]==0){
		printf("%d",0);return 0;}
	int min=MAX;
	for(i=1;i<=n;i++){
		int sum=(i-b[i])+b[n]-b[i];
		if(sum<min)
			min=sum;
	}
	printf("%d",min);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator