• 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;
    }
    
  • 相关阅读:
    一份感动到哭的成绩单……
    永远不要、不要、不要、不要放弃
    FusionChart 保存图片 小强斋
    JfreeChart的使用 小强斋
    JFreeChart中文API 小强斋
    FusionChart 小强斋
    面试题>旋转字符串 小强斋
    Dom4j 小强斋
    FusionChart 保存图片 小强斋
    JFreeChart中文API 小强斋
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11645364.html
Copyright © 2020-2023  润新知