代码:
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
int a[110],b[110];
int main()
{
int i,j,n;
for (i=0; i<20; i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
int ans1=0;
for (i=0; i<20; i++)
{
if (a[i]==1)
{
if (i==19)
{
ans1=inf;
break;
}
a[i]=1-a[i];
a[i+1]=1-a[i+1];
a[i+2]=1-a[i+2];
ans1++;
}
}
int ans2=0;
for (i=19; i>=0; i--)
{
if (b[i]==1)
{
if (i==0)
{
ans2=inf;
break;
}
b[i]=1-b[i];
b[i-1]=1-b[i-1];
b[i-2]=1-b[i-2];
ans2++;
}
}
printf("%d\n",min(ans1,ans2));
return 0;
}