Codeforces 1077B Disturbed People(思维题)

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.

题目大意:

有一溜房间,然后如果你的房间关灯了 然后你左边和右边的房间都没关灯,那你就被打扰了,如果本来开着灯的,就不会被打扰到了(你自己开着灯,都打扰别人了还会被别人打扰蛮)
问最少需要关几个房间的灯 让所有人都不被打扰
开灯就是1 关灯就是0;

解题思路:

我们要保证没有人被打扰,就是不存在 101这种情况,然后我们从左向右扫,如果扫到0,我们再判断一下他的左右是否都是1 ,如果都是1 我们就必须关左右其中一个,关哪个呢?肯定是关右边的啦,因为左边的已经是扫过了的,右边的灯关了,还有可能让后面被打扰的人不被打扰,有一丢丢贪心的思想。。就这样扫一遍就出来了。。贼简单

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int a[110];
int main()
{int ans=0;while(cin>>n){ans=0;for(int i=1;i<=n;i++)cin>>a[i];for(int i=2;i<n;i++){if(a[i]==0){if(a[i-1]==1&&a[i+1]==1){a[i+1]=0;ans++;}}}cout<<ans<<endl;}return 0;
}

Codeforces 1077B Disturbed People(思维题)相关推荐

  1. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

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

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

  3. Codeforces 1077b Disturbed People

    题目链接 : http://codeforces.com/problemset/problem/1077/B   B. Disturbed People There is a house with n ...

  4. CodeForces - 298B Sail (思维题)

    CodeForces - 298B Sail The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey ...

  5. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

  6. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  7. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  8. ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

    题干: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After tha ...

  9. Educational Codeforces Round 67 (Rated for Div. 2)(D思维题 线段树/E树形dp(换根dp) 二次扫描与换根法)

    心得 D写了个假算法被hack了wtcl- E据涛神说是二次扫描与换根法,看了看好像和树形dp差不多 F概率dp G费用流 回头再补 思路来源 马老师 归神 贤神等代码 http://www.mami ...

最新文章

  1. mysql 中文字符查询不出数据_jsp页面显示不出mysql中查询出的中文字符串,插入中文也不好使...
  2. Jmeter脚本录制(APP)
  3. poj 1186 方程的解数(线性探测再哈希)
  4. 如何HttpWebRequest模拟登陆,获取服务端返回Cookie以便登录请求后使用
  5. test - delete category 060 in X3C - R3MATCLASS and perform customizing download
  6. spring学习(1):初始项目
  7. 《那些年啊,那些事——一个程序员的奋斗史》——115
  8. 小米机器人清理主刷和轴承_扫地机主刷怎样更换
  9. python 时间_Python-基础-时间日期处理小结
  10. c++ opencv实现区域填充_利用opencv之为图像添加边框
  11. Numpy入门(详看注释)
  12. 一篇 JPA 总结
  13. 艾宾浩斯遗忘曲线复习计划表Excel下载
  14. 聊聊flink的consecutive windowed operations 1
  15. python文件批量改名
  16. 网络渗透中的指纹识别
  17. 陈臣java_小菜学设计模式——享元模式
  18. RobotFramework入门(一)简要介绍及使用
  19. html5 斜边,css斜切角 斜边 倒角
  20. 为黑客打工能挣多少?月薪最高达2万美元

热门文章

  1. 对话即平台,一场对长尾理论的逆向革命
  2. Espresso之RecyclerView
  3. 提高百度SEM竞价托管效果常见的4大问题
  4. html渲染json的插件,lottieJS(Json动画的使用)
  5. html如何设置滚动动画,滚动条触发CSS3动画
  6. think php5 离线手册,thinkphp5.0离线手册下载
  7. latex 调整图片大小
  8. 烤仔TVのCCW丨密码学通识(五)消息认证码
  9. 读季琦《创始人·手记》
  10. 《真·三国无双ADVANCE》攻略