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;
}
原文地址:https://www.cnblogs.com/rainydays/p/1948650.html