| ||||||||||
| 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)过!#include<stdio.h>
#define Max 30010
int main()
{
int a[Max];
int i;
int n;
int j;
int k;
int length;
int sum;
fscanf(stdin, "%d", &n);
length = n; sum = 0;
i = 0; j = 0;
while(n--)
{
fscanf(stdin, "%d", &k);
if (k == 1)
{
j++;
}
else
{
sum += j;
a[i++] = j;
j = 0;
}
}
k = sum + j;
sum = 0;
for (j=0; j<i; j++)
{
if (a[j] + i - j + sum > k)
{
k = a[j] + i - j + sum;
}
sum += a[j];
}
printf("%d", length - k);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator