B. Koala and Lights-Codeforces Round #584( Div. 1 + Div. 2)

题目传送门
B. Koala and Lights
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
The first line contains a single integer n (1≤n≤100), the number of lights.

The next line contains a string s of n characters. The i-th character is “1”, if the i-th lamp is initially on. Otherwise, i-th character is “0”.

The i-th of the following n lines contains two integers ai and bi (1≤ai,bi≤5) — the parameters of the i-th light.

Output
Print a single integer — the maximum number of lights that will ever be on at the same time.

Examples
inputCopy
3
101
3 3
3 2
3 1
outputCopy
2
inputCopy
4
1111
3 4
5 2
3 1
3 2
outputCopy
4
inputCopy
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
outputCopy
6
Note
For first example, the lamps’ states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).

In the second example, all lights are initially on. So the answer is 4.

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define ll long long
#define p 99824433
const int N=1e2+15;
int a[N],b[N];
char s[N];
ll ww(ll a,ll b)
{
    ll ans = 0;
    while (b)
    {
        if (b & 1)
        {
            ans = (ans + a)%p;
        }
        a = (a + a)%p;
        b >>= 1;
    }
    return ans;
}
char vis(char a)
{
    if(a=='0')
        return '1';
    return '0';
}
ll yy(ll a, ll b)
{
    ll ans=1;
    while(b)
    {
        if(b & 1) ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    cin>>s;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
    }
    int t;
    int ans=0;
    int sum=0;
    int ss=0;
    for(int j=1; j<n*1010; j++)
    {
        t=0;
        for(int i=0; i<n; i++)
        {
            if(!ss)if(s[i]=='1')sum++;
            if(j>=b[i]&&!((j-b[i])%a[i]))
                s[i]=vis(s[i]);
            if(s[i]=='1')t++;
        }
        ss=1;
        ans=max(t,ans);
    }
    cout<<max(ans,sum);
    return 0;
}
全部评论

相关推荐

06-27 12:30
延安大学 C++
实习+外包,这两个公司底层融为一体了,如何评价呢?
一表renzha:之前面了一家外包的大模型,基本上都能答出来,那面试官感觉还没我懂,然后把我挂了,我都还没嫌弃他是外包,他把我挂了……
点赞 评论 收藏
分享
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
点赞 评论 收藏
分享
有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务