zoukankan      html  css  js  c++  java
  • Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest

    链接:https://codeforces.com/contest/1141/problem/B

    题意:

    给n个数,0代表工作,1代表休息,求能连续最大的休息长度。

    可以连接首尾。

    思路:

    求普通连续,当第一个时间和最后一个时间都休息的时候加上去判断一下。

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long LL;
    
    const int MAXN = 2e5;
    int r[MAXN];
    
    int main()
    {
        int flag = 1;
        int n, o;
        int pos = 1;
        int res = 0;
        cin >> n;
        for (int i = 1;i <= n;i++)
        {
            cin >> o;
            if (o == 1)
                r[pos]++;
            else
                pos++;
            if (i == 1 && o == 0)
                flag = 0;
            if (i == n && o == 0)
                flag = 0;
            res = max(res, r[pos]);
        }
        if (flag)
            res = max(res, r[1] + r[pos]);
        cout << res << endl;
    
        return 0;
    }
    

      

  • 相关阅读:
    Circular vector
    【杂题】进制转换
    【POJ】3006
    【POJ】1503
    【POJ】2262
    【POJ】1083
    【POJ】2739
    对拍
    【POJ】2159
    【POJ】3299
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10570950.html
Copyright © 2011-2022 走看看