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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值