1. 程式人生 > >Codeforces Round #521 (Div. 3) B. Disturbed People

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

題解

題目大意 n個燈0關燈1開燈 101則中間的睡不著 問最少關掉多少個燈可以全都能睡著

遇見101則將後面的1的燈泡關掉 這樣解決10101的問題 計數輸出即可

AC程式碼

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e2 + 10;
int a[MAXN];

int main()
{
#ifdef LOCAL
	freopen("C:/input.txt"
, "r", stdin); #endif int N; cin >> N; for (int i = 1; i <= N; i++) scanf("%d", &a[i]); int cnt = 0; for (int i = 2; i < N; i++) if (a[i - 1] && !a[i] && a[i + 1]) //101則將後面的關閉 a[i + 1] = 0, cnt++; cout << cnt << endl; return 0; }