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;
    }
    
  • 相关阅读:
    php解析XML的两种方法
    Windows下xampp搭配php环境以及mysql的设置和php连接Mysql数据库
    管道
    Ubuntu文件系统
    Ubuntu如何使用Vscode写C++代码
    Ubuntu如何百度云盘下载
    Debug程序的使用
    寄存器
    汇编指令
    汇编第二章_寄存器
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11645364.html
Copyright © 2011-2022 走看看