CF1077B.Disturbed People
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a1,a2,…,an, where ai=1 if in the i-th flat the light is on and ai=0 otherwise.
Vova thinks that people in the i-th flats are disturbed and cannot sleep if and only if 1<i<n and ai−1=ai+1=1 and ai=0.
Vova is concerned by the following question: what is the minimum number k such that if people from exactly k pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number k.
Berlatov 主街上有一栋包含 n 套公寓的住宅楼。Vova 每晚都会观察这栋住宅楼。该住宅楼可表示为一个长度为 n 的整数数组 a1,a2,…,an,其中若第 i 套公寓的灯亮着,则 ai=1;否则 ai=0。
Vova 认为:当且仅当 1<i<n,且 ai−1=ai+1=1、ai=0 时,第 i 套公寓中的人会受到干扰而无法入睡。
Vova 关心如下问题:最少需要让恰好 k 个互不相同的公寓关灯,才能确保无人受到干扰?你的任务就是求出这个最小的 k 值。
输入格式
The first line of the input contains one integer n (3≤n≤100) — the number of flats in the house.
The second line of the input contains n integers a1,a2,…,an (ai∈0,1), where ai is the state of light in the i-th flat.
输入的第一行包含一个整数 n(3≤n≤100)—— 表示楼内公寓的数量。
输入的第二行包含 n 个整数 a1,a2,…,an(其中 ai∈{0,1}),ai 表示第 i 个公寓的灯光状态。
输出格式
Print only one integer — the minimum number k such that if people from exactly k pairwise distinct flats will turn off the light then nobody will be disturbed.
仅输出一个整数——最小的数 k,使得恰好有来自 k 个两两不同的公寓的人关掉灯光时,不会打扰到任何人。
输入输出样例
输入#1
10 1 1 0 1 1 0 1 0 1 0
输出#1
2
输入#2
5 1 1 0 0 0
输出#2
0
输入#3
4 1 1 1 1
输出#3
0
说明/提示
In the first example people from flats 2 and 7 or 4 and 7 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.
在第一个例子中,住在公寓 2 和 7 或 4 和 7 的人可以关掉灯,且不会打扰任何人。可以证明,在该例子中不存在更优的答案。
第二个和第三个例子中均无人被打扰。
输入解题思路,AI测评打分。不知道怎么写?