zoukankan      html  css  js  c++  java
  • Codeforces Round #584 B. Koala and Lights

    链接:

    https://codeforces.com/contest/1209/problem/B

    题意:

    It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.

    After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters ai and bi. Light with parameters ai and bi will toggle (on to off, or off to on) every ai seconds starting from the bi-th second. In other words, it will toggle at the moments bi, bi+ai, bi+2⋅ai and so on.

    You know for each light whether it's initially on or off and its corresponding parameters ai and bi. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.

    Here is a graphic for the first example.

    思路:

    枚举到1e5, 然后每次判断开了多少灯.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int n;
    int a[110], b[110];
    int fi[110];
    char s[110];
    
    int main()
    {
        cin >> n;
        cin >> s;
        int res = 0;
        for (int i = 1;i <= n;i++)
            cin >> a[i] >> b[i];
        for (int i = 0;i < n;i++)
        {
            fi[i+1] = s[i]-'0';
            if (s[i] == '1')
                res++;
        }
        for (int i = 1;i <= 100000;i++)
        {
            int tmp = 0;
            for (int j = 1;j <= n;j++)
            {
                if (i < b[j])
                {
                    if (fi[j] == 1)
                        tmp++;
                    continue;
                }
                int cnt = 1+(i-b[j])/a[j];
                if ((fi[j] == 1 && cnt%2 == 0) || (fi[j] == 0 && cnt%2 == 1))
                    tmp++;
    //            cout << tmp << ' ';
            }
    //        cout << i << ' ' << tmp << endl;
            res = max(res, tmp);
        }
        cout << res << endl;
    
        return 0;
    }
    
  • 相关阅读:
    内存分配问题
    C++ assert 的一点说明
    强大的stringstream
    C++中随机数
    C++ 中new
    C++ 中string 详解 转载自 博客园
    未命名名字空间
    使用ifstream和getline读取文件内容[c++]
    6.bootstrap练习笔记-缩略图和list-group
    3.bootstrap练习笔记-媒体内容
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11645364.html
Copyright © 2011-2022 走看看