Disturbed People_CodeForces1077B

在一条街道上,有n间房子,每间房子的灯可能是开或关。如果一间房子关灯,且其左右邻居开灯,则该房子的人会受到打扰。任务是找出至少需要关闭多少盏灯,以确保没有人被打扰。通过模拟算法,从左至右检查每一间房子,若发现被打扰的情况,选择关闭右边邻居的灯,以此策略寻找最小的关灯数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目

 

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 nninteger 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 aiaiis the state of light in the ii-th flat.

Output

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

Examples

Input

10
1 1 0 1 1 0 1 0 1 0

Output

2

Input

5
1 1 0 0 0

Output

0

Input

4
1 1 1 1

Output

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.

 题目大意

有一条街道,街道上有n间房子,如果某一间房子关着灯,而他左边、右边的房子都开着灯,那么他就会被打扰。

输入一个n

然后输入n个数字:0或者是1  0代表关灯,1代表开灯

要求求出最少关闭几间房子的灯就能使所有人都不被打扰

算法:模拟 

思路分析 

 一开始想到这么几种情况:101101关两个  10101关一个

但后来想只要时他关灯,左右都不关就会被打扰,然后我想她不被打扰,那我就去关掉左右中的一个灯就好了,那我每次都关掉右边的灯就好了(后边会讲到为什么关右边)

先找到第一个被打扰的房子,关掉它右边的灯,再去找第二个,关掉它右边的灯......遍历到最后一个被打扰的房子

10101这种情况 关掉第一个0后边的那个灯之后,第二个零就不被打扰了

101101这种情况 关掉第一个0后边的那个灯之后,第二个零还会被打扰,继续找第二个被打扰的房子

(至于为什么每次都关掉右边的灯:因为我是从第一个被打扰的房子开始判断的,我关掉左边的话,确实是第一个不会被打扰了,但这样就没法达到一次解决两个房子的问题,还是10101这个 我关掉第一个0左边的那个灯之后,第二个零还是会被被打扰了,那就还需要关一个灯,这个关右边的灯就是解决这个问题的关键

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cherish_lii

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值