poj3671

枚举分界线的位置,不要忘了最左侧的分界线

 

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

const int maxn = 30005;

int main()
{
	//freopen("D:\\t.txt", "r", stdin);
	int n;
	scanf("%d", &n);
	int tot1 = 0;
	int left1[maxn];
	for (int i = 0; i < n; i++)
	{
		int a;
		scanf("%d", &a);
		if (a == 1)
			tot1++;
		left1[i] = tot1;
	}
	int ans = tot1;
	for (int i = 0; i < n; i++)
	{
		if (ans > i + 1 - left1[i] + tot1 - left1[i])
			ans = i + 1 - left1[i] + tot1 - left1[i];
	}
	printf("%d\n", ans);
	return 0;
}
posted @ 2011-02-01 13:51  金海峰  阅读(272)  评论(0编辑  收藏  举报