zoukankan      html  css  js  c++  java
  • 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 ai1=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.

    Input

    The first line of the input contains one integer nn (3n1003≤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.

    Output

    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.

    Examples
    input
    Copy
    10
    1 1 0 1 1 0 1 0 1 0
    
    output
    Copy
    2
    
    input
    Copy
    5
    1 1 0 0 0
    
    output
    Copy
    0
    
    input
    Copy
    4
    1 1 1 1
    
    output
    Copy
    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
    ", ans);
        return 0;
    }
    

      

    让人捉鸡的英语理解能力。。。难受

  • 相关阅读:
    (转)C#中的那些全局异常捕获
    mysql 5.7 MGR
    mysql 5.7 MGR
    perl 获取响应头
    python 获取响应头
    研究生开咖啡厅,年盈利15万,欲打造重庆咖啡文化
    女学生经营二手服装租赁,年营业额突破300万
    在校学生看中餐饮外送行业,企业估值500亿
    导演跨界跳入椰子水“新泳池”,一举占领椰子产品市场
    在校女学生,掌管27家卤味连锁店
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9990723.html
Copyright © 2011-2022 走看看