链接:

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;
}

Codeforces Round #584 B. Koala and Lights的更多相关文章

  1. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  2. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  3. Codeforces Round #168 (Div. 2)---A. Lights Out

    Lights Out time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  5. Codeforces Round #584 D. Cow and Snacks

    链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...

  6. Codeforces Round #584 C. Paint the Digits

    链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...

  7. Codeforces Round #584 A. Paint the Numbers

    链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...

  8. Codeforces Round 584 题解

    -- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...

  9. Codeforces Round #584 (Div. 1 + Div. 2)

    Contest Page A sol 每次选最小的,然后把它的所有倍数都删掉. #include<bits/stdc++.h> using namespace std; int read( ...

随机推荐

  1. 列表初始化(list initialization)

    列表初始化啊就是大括号来初始化: 列表初始化的好处:

  2. springboot 集成fastDfs

    pom.xml 引入依赖 <dependency> <groupId>com.github.tobato</groupId> <artifactId>f ...

  3. PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  4. (五)Maven中的聚合和继承

    一.为什么要聚合? 定义:我们在开发过程中,创建了2个以上的模块,每个模块都是一个独立的maven project,在开始的时候我们可以独立的编译和测试运行每个模块,但是随着项目的不断变大和复杂化,我 ...

  5. (四)springmvc之获取servlet原生对象

    一.使用DI注入的方式 <a href="<%=request.getContextPath()%>/servletObj_1">DI注入的方式</a ...

  6. Spring Boot Redis 分布式缓存的使用

    一.pom 依赖 <!-- 分布式缓存 --> <dependency> <groupId>org.springframework.boot</groupId ...

  7. vue html属性绑定

    业务场景: element ui里面select的组件,通过勾选是否启动搜索功能 解决: 在select组件上绑定一个 :filterable,值就是是否可搜索的checkbox的值  true和fa ...

  8. c#NPOI导出2007版本excel

    2003和2007版本区别: HSSFWorkbook(2003) IWorkbook(2007版本) 写完之后会有个问题,导出会报错[流已关闭]. NPOI生产.xlsx文件件时,在使用book.W ...

  9. springboot和Redis集群版的整合

    此篇接上一个文章springboot和Redis单机版的整合 https://www.cnblogs.com/lin530/p/12019023.html 下面接着介绍和Redis集群版的整合. 1. ...

  10. OGG 自动重启脚本

    6-20 * * * /oggdata/log/oggautorestart.sh >/oggdata/log/crontab_oggautorestart.log 2>&1 [说 ...