链接:

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. 记crt 在windows与linux服务器之间利用ftp进行文件的上传下载

    我们首先来熟悉一些相关的命令以及操作: ls      #展示linux服务器当前工作目录[你连接sftp时所处的目录]下的所有文件以及文件夹 lcd  F:\niki      #绑定你在windo ...

  2. Servlet 响应及请求信息

    // 文件路径 D:\ApacheServer\web_java\HelloWorld\src\com\test\TestServletRequestrResponse.java package co ...

  3. Java 代码读取properties文件

    jdk1.6 package read;import java.io.File;import java.io.FileInputStream;import java.io.IOException;im ...

  4. PHP二维数组的引用赋值容易犯的错误

    大家一起来分析一下下面这段代码: <?php $arr = array(); $arr["abc"] = array("sex" => 100, & ...

  5. wordpress 图片上传时发生了错误,请稍后再试 的解决办法

    前一天网站还是好好的,仅一天过后就显示图片无法上传,百思不得其解 上下百度,大多数帖子提供的解决办法对我都不适用,继续搜,最后发现一篇帖子中提到是wp-config的编码格式问题 想到昨天刚好修改了下 ...

  6. const关键字的使用——C语言

    一.常规用法 关键字const用来定义只读变量,被const定义的变量它的值是不允许改变的,即不允许给它重新赋值,即使是赋相同的值也不可以.所以说它定义的是只读变量,这也就意味着必须在定义的时候就给它 ...

  7. 理解 is_callable

    官方解释: (PHP 4 >= 4.0.6, PHP 5, PHP 7) is_callable — 检测参数是否为合法的可调用结构. 说明 is_callable ( callable $na ...

  8. Typora 的使用

    一. Typora的markdown语法 1.标题 使用简单的ctr+数字健,就可以快速完成各种级别的标题 #一阶标题 或者快捷键Ctrl+1 ##二阶标题 或者快捷键Ctrl+2 ##二阶标题 或者 ...

  9. linux上启动tomcat报错:Failed to read schema document 'http://www.springframework.org/schema/data/mongo/spring-mongo-2.0.xsd

    本文原文连接: http://blog.csdn.net/bluishglc/article/details/7596118 ,转载请注明出处! spring在加载xsd文件时总是先试图在本地查找xs ...

  10. [javascript]原生js实现Ajax

    一.首先看JQuery提供的Ajax方法: $.ajax({ url: , type: '', dataType: '', data: { }, success: function(){ }, err ...