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
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.

这个题目,其实遍历一遍就好了,如果出现了101这种情况,就把右边的灯关了,然后就这样
代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;const int maxx=101;
int a[maxx];
int n;int main()
{while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));for(int i=0;i<n;i++){scanf("%d",&a[i]);}int sum=0;for(int i=0;i<n;i++){if(i&&i!=n-1){if(a[i]==0&&a[i-1]==1&&a[i+1]==1){a[i+1]=0;sum++;}}}printf("%d\n",sum);}}

努力加油a啊,(o)/~

Disturbed People(思维)相关推荐

  1. Codeforces Round #521 (Div. 3) B. Disturbed People 思维

    题解 题目大意 n个灯0关灯1开灯 101则中间的睡不着 问最少关掉多少个灯可以全都能睡着 遇见101则将后面的1的灯泡关掉 这样解决10101的问题 计数输出即可 AC代码 #include < ...

  2. Codeforces 1077B Disturbed People(思维题)

    Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...

  3. 【Disturbed People】【CodeForces - 1077B】(思维水题)

    题目: There is a house with nn flats situated on the main street of Berlatov. Vova is watching this ho ...

  4. 《英语语法新思维初级教程》学习笔记(三)冠词

    参考资料: 1. <英语语法新思维初级教程> 2. 英语国际英标表 ▶ 知识点 ▼ 限定词的是对名词起限定作用的各类词的总称,具体作用有限定名词所指的范围,对名词起泛指或特指.定量或或不定 ...

  5. 揭富人与穷人21个不同思维 看富豪如何脱颖而出

    <富人是怎么想的>(How Rich People Think)的作者Steve Siebold曾在近30年里采访世界各地的富豪,看究竟是什么让富豪从普通人中站出来. 他发现这和金钱基本没 ...

  6. 学习,思维三部曲:WHAT、HOW、WHY

    学习技术的三部曲:WHAT HOW WHY 我把学习归类为三个步骤:What.How.Why.经过我对周围同事和朋友的观察,大部分感觉自己技术没有提高的人,都仅仅停留在What阶段.下面我把这三个步骤 ...

  7. Linux架构思维导图

    Linux架构思维导图 GUI(Graphical User Interface,图形用户界面) Linux 学习路径 软件框架 Linux 桌面介绍 FHS:文件系统目录标准 Linux 需要特别注 ...

  8. github 思维导图开元软件_画思维导图记笔记的工具软件

    思维导图是很多人在做笔记的时候都会用到的一种记录方式,使用思维导图可以简单有效的表达发散性思维,能够协助人们在各种因素间平衡展开思考,从而提升自己笔记的含金量和工作效率,有没有画思维导图记笔记的工具软 ...

  9. 大数据概念思维导图_思维导图|数据化风控(信用评分建模教程)

    本文将按<数据化风控--信用评分建模教程>行文逻辑,并结合相关参考材料,为大家梳理本书涉及的重点知识,也算是自己读书笔记分享.有需要的同学可先收藏.点赞,以便回顾学习和吸收,当然,如果愿意 ...

最新文章

  1. 机器学习模拟1亿原子:中美团队获2020「超算诺贝尔奖」戈登贝尔奖
  2. 模板or定制网站如何选?
  3. linux安装mysql社区版 rpm_linux系统rpm包安装mysql
  4. 关于优酷开放SDK相应的mediaplayer的监听器的设置之setOnBufferingUpdateListener
  5. poj 2057 树形DP,数学期望
  6. SQL Server 2005参考:PIVOT
  7. C# StreamReader.ReadLine统计行数的问题
  8. 阿里云Centos镜像源和EPEL源
  9. 针织erp_编程源于我们长期的针织工作
  10. [批处理]NetstatFilter快速查找端口被占用问题
  11. 查看网络抖动_Linux下3种常用的网络测速工具
  12. Hive 连接 HBase 错误处理
  13. css设置字体的行数,超出显示...
  14. linux下安装配置laravel环境,linux下的laravel安装
  15. 【微信小程序开发】 踩坑 抽奖幸运大转盘 完美实战
  16. 突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘
  17. excel导出图片---HSSFWorkbook--SXSSFWorkbook
  18. 0667-6.2.0-什么是Cloudera虚拟私有集群和SDX
  19. 如何在jupyter中执行带参数的py文件
  20. 学生管理系统登录部分

热门文章

  1. IOS开发基础之网易新闻UICollectionView的使用第3天
  2. uniapp中实现每次点击左侧菜单右边区域都从顶部开始
  3. python包括哪些部分_第一部分 Python基础篇
  4. linux tomcat 日志乱码,Linux下TOMCAT中日志出现中文乱码
  5. 单例模式【SingletonPattern】
  6. 菜单自定义图标_操作系统任务栏了解多少,Windows server 2008 R2自定义通知区域...
  7. 手动安装android的sdk
  8. android studio 65536错误的解决
  9. Android内存泄漏
  10. 多文件,多目录下查询关键字脚本