B. Disturbed People

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jj12345jj198999/article/details/84698989

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of nn integer numbers a1,a2,…,ana1,a2,…,an, where ai=1ai=1 if in the ii-th flat the light is on and ai=0ai=0 otherwise.

Vova thinks that people in the ii-th flats are disturbed and cannot sleep if and only if 1<i<n1<i<n and ai−1=ai+1=1ai−1=ai+1=1 and ai=0ai=0.

Vova is concerned by the following question: what is the minimum number kk such that if people from exactly kk pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number kk.

Input

The first line of the input contains one integer nn (3≤n≤1003≤n≤100) — the number of flats in the house.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (ai∈{0,1}ai∈{0,1}), where aiai is the state of light in the ii-th flat.

Output

Print only one integer — the minimum number kk such that if people from exactly kk pairwise distinct flats will turn off the light then nobody will be disturbed.

Examples

input

Copy

10
1 1 0 1 1 0 1 0 1 0

output

Copy

2

input

Copy

5
1 1 0 0 0

output

Copy

0

input

Copy

4
1 1 1 1

output

Copy

0

Note

In the first example people from flats 22 and 77 or 44 and 77 can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.

There are no disturbed people in second and third examples.

解题说明:此题是一道模拟题,可以直接遍历,如果a[i-1]和a[i+1]都为1,且a[i]为0,则至少需要关闭一盏灯才能保证不被打扰。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	int a[110], i, c = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (i = 1; i<n - 1; i++) 
	{
		if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0)
		{
			c++;
			i += 2;
		}
	}
	printf("%d\n", c);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/jj12345jj198999/article/details/84698989