原题链接: https://codeforces.com/contest/1077/problem/B
样例:
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代码:
/*
*
*/
//POJ不支持
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
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;
}