欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)

程序员文章站 2022-06-04 18:57:04
...

原题链接: https://codeforces.com/contest/1077/problem/B

B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)
样例:

Examples
Input
10
1 1 0 1 1 0 1 0 1 0
Output
2
Input
5
1 1 0 0 1
Output
0
Input
4
1 1 1 1
Output
0

题意: 对于along,他认为只要一个寝室关了灯,而与该寝室相邻的灯都亮着的话,那么他就会改变这种状态,即断掉其中一个寝室的闸门。问给定一系列寝室的状态。问along不想看到别人孤独需要断掉的寝室闸门最小数。

解题思路: 对于该题,我们直接模拟即可,找到关灯的寝室然后判断相邻寝室是否都亮着,若亮着把右边的关掉(为了使断闸数最小,关右边可以使解最优),并统计断闸次数。则此题易解。

AC代码:

/*
*邮箱:aaa@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e2+2;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int n,a[maxn];
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>n){
		rep(i,0,n-1)cin>>a[i];
		int sum=0;
		rep(i,1,n-2){
			if(a[i]==0&&a[i-1]==1&&a[i+1]==1){
				sum++;
				a[i+1]=0;
				i++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}