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;
}
全部评论

相关推荐

04-02 10:09
门头沟学院 Java
用微笑面对困难:这里面问题还是很多的,我也不清楚为啥大家会感觉没啥问题。首先就是全栈开发实习9个月的内容都没有java实习生的内容多,1整个技术栈没看出太核心和难点的内容,感觉好像被拉过去打杂了,而且全栈基本上很容易被毙。里面能问的bug是在太多了比如L:继承 BaseMapper 可直接使用内置方法’。请问你的 BaseMapper 是如何扫描实体类注解如果瞬时产生 100 个上传任务,MySQL 的索引设计是否会有瓶颈?你做过分库分表或者索引优化吗?全栈的内容可以针对动态难点去搞,技能特长写在下面吧,你写了这么多技能,项目和实习体现了多少?你可以在项目里多做文章然后把这个放下去,从大致来看实习不算太水,有含金量你也要写上内容针对哨兵里面的节点变化能问出一万个问题,这个很容易就爆了。
提前批简历挂麻了怎么办
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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