Disturbed People_CodeForces1077B
题目
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左边的那个灯之后,第二个零还是会被被打扰了,那就还需要关一个灯,这个关右边的灯就是解决这个问题的关键
Disturbed People_CodeForces1077B相关推荐
- Disturbed People(思维)
There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...
- 【Disturbed People】【CodeForces - 1077B】(思维水题)
题目: There is a house with nn flats situated on the main street of Berlatov. Vova is watching this ho ...
- 【Paper】2022_Fixed-Time Cooperative Tracking for Delayed Disturbed Multi-Agent Systems Under Dynamic
2022_Fixed-Time Cooperative Tracking for Delayed Disturbed Multi-Agent Systems Under Dynamic Event-T ...
- Codeforces Round #521 (Div. 3) B. Disturbed People
There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...
- Codeforces 1077b Disturbed People
题目链接 : http://codeforces.com/problemset/problem/1077/B B. Disturbed People There is a house with n ...
- Codeforces 1077B Disturbed People(思维题)
Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...
- Disturbed People CodeForces - 1077B
贪心题,先关掉那些管一个灯造福两个寝室的,然后一边关灯一边统计一边继续向后判断.最后加上那些依然还受影响的寝室数(只要受影响我一定要关一盏灯),不废话,看代码: #include <iostre ...
- B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)
原题链接: https://codeforces.com/contest/1077/problem/B 样例: Examples Input 10 1 1 0 1 1 0 1 0 1 0 Output ...
最新文章
- Python2.x爬虫入门之URLError异常处理
- Node 即学即用 笔记 思维导图
- UVA - 10934 Dropping water balloons(装满水的气球)(dp)
- 实际工作中,一个完整的可视化大屏项目有哪些步骤?
- Transformer 是万能的吗?
- 用Maven创建第一个web项目Struts2项目
- PHP Mysql or条件排序问题
- 北京圣思园java视频教程全套_北京圣思园Java8新特性及实战视频教程完整版
- 格力空调售后服务管理系统
- linux addr2line 用法,addr2line的用法
- elipse配色方案
- 经典SFM步骤——Lowe2005
- 深入Scala系列之一组件重用
- 正心,修身,方能齐家,治国,平天下
- OPENSSL FIPS
- 08.音频系统:第002节_Android音频系统框架简述
- (JAVA)获取支付宝二维码 带参数
- 一文带你全面了解MVC、MVP、MVVM模式(实例讲解)
- mysql通过卡号识别银行_Java 根据银行卡号获取银行名称以及图标
- 逆向windows“恶搞锁机”程序