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 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.
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.
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.
10
1 1 0 1 1 0 1 0 1 0
2
5
1 1 0 0 0
0
4
1 1 1 1
0
题解:刚开始没看懂题意后来找了翻译 炒鸡简单 如果 a[i] = 0 && a[i - 1] = 1 && a[i + 1] = 1 那么 i 会被影响 应该关掉 a[i + 1] 的灯,即变成 $0$
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int n;
int a[maxn]; int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &a[i]); int ans = 0;
for(int i = 2; i < n; i ++) {
if(a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) {
ans ++;
a[i + 1] = 0;
}
}
printf("%d\n", ans);
return 0;
}
让人捉鸡的英语理解能力。。。难受
CodeForces Round #521 (Div.3) B. Disturbed People的更多相关文章
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】
任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...
- CodeForces Round #521 (Div.3) E. Thematic Contests
http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...
- CodeForces Round #521 (Div.3) D. Cutting Out
http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...
- Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...
- CodeForces Round #521 (Div.3) A. Frog Jumping
http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...
- Codeforces Round #521 (Div.3)题解
A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...
- Codeforces Round #521 (Div. 3)
B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过. D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...
- Codeforces Round #521 Div. 3 玩耍记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
随机推荐
- python实现栈的算法
以下来源“悟空”的讲课视频,我只是对内容加深以下理解,做一些说明: 栈作为一种数据结构,是一种只能在一端进行插入和删除操作.它按照先进后出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要 ...
- java—三大框架详解,其发展过程及掌握的Java技术慨括
Struts.Hibernate和Spring是我们Java开发中的常用关键,他们分别针对不同的应用场景给出最合适的解决方案.但你是否知道,这些知名框架最初是怎样产生的? 我们知道,传统的Java W ...
- 配置dubbo架构的maven项目
1. 拆分工程 1)将表现层工程独立出来: e3-manager-web 2)将原来的e3-manager改为如下结构 e3-manager |--e3-manager-dao |--e3-manag ...
- java基础面试题:说说&和&&的区别
&与&&都是逻辑与 不同的是&左右两边的判断都要进行,而&&是短路与,当&&左边条件为假则不用再判断右边条件,所以效率更高 例如,对于i ...
- Java 窗体的基本操作语句 JFrame
package com.swift; import java.awt.Color; import java.awt.GridLayout; import java.util.Random; impor ...
- Linux 命令大全提供 500 多个 Linux 命令搜索
Linux Command 在这里维持一个持续更新的地方 516 个 Linux 命令大全,内容包含 Linux 命令手册.详解.学习,值得收藏的 Linux 命令速查手册.请原谅我写了个爬虫,爬了他 ...
- C++ 无限定名称查找
无限定名称查找 (关键字:懒惰,挑捡,using指令的特殊性) 无限定名称查找实际上就是指没有限定(名称空间和名称空间运算符)名存在的一个名字的出现,其中对于using指令,其内部包含的所有的声明是被 ...
- 六、Shell echo命令
Shell echo命令 Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出.命令格式: echo string 您可以使用echo实现更复杂的输出格式控制. 1. ...
- k8s资源配置清单的书写格式(yaml文件)
yaml文件书写格式:5大类:apiVersion: 选择kubectl api-versions里面存在的版本kind: 选择kubectl api-resources结果中的对象资源metadat ...
- java中常用的swing组件 (2013-10-27-163 写的日志迁移
五种布局: 流式布局(FlowLayout)边界布局(borderLayout)网格布局(GridLayout) 盒子布局(BoxLaYout) 空布局(null) 常用的几种 卡片布局(C ...