Codeforces Round #584 B. Koala and Lights
链接:
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的更多相关文章
- Codeforces Round #584
传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- 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 ...
- Codeforces Round #584 E2. Rotate Columns (hard version)
链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...
- Codeforces Round #584 D. Cow and Snacks
链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...
- Codeforces Round #584 C. Paint the Digits
链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...
- Codeforces Round #584 A. Paint the Numbers
链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...
- Codeforces Round 584 题解
-- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...
- Codeforces Round #584 (Div. 1 + Div. 2)
Contest Page A sol 每次选最小的,然后把它的所有倍数都删掉. #include<bits/stdc++.h> using namespace std; int read( ...
随机推荐
- JS 通过注册表调用启动本地软件
(关键点:所有软件安装的注册表路径是不会变化的,这个注册表路径需沟通软件商家获取或者通过自己安装在注册表中查找得到) // 调用 注册表编辑类 方法 function run_jxpgj(){//进项 ...
- 使用内存地址点亮LED—跟51单片机一样写代码教学(初步入门)
51单片机点亮一个小灯 #include <rge52.h> sbit LED = P0^ void main(void) { P0 = 0XFE; // 总线操作 sfr P0 0X80 ...
- Scratch 3.0,新在哪里?
大家期待已久的Scratch 3.0,已经上线一段时间了. 学生们可轻松通过连接WeDo2.0和EV3机器人 进行scratch编程学习啦! 或许有些朋友还不太了解Scratch,没关系,小乐今天就为 ...
- 读取一整行,保留空白,直到遇到换行符:getline()
- (十六)客户端验证与struts2中的服务器端验证
一.客户端验证: 即用javaScript来验证. <%@ page language="java" contentType="text/html; charset ...
- (一)Centos之VMware虚拟机安装
一.下载 64位的VM12 安装包: http://pan.baidu.com/s/1bpzoXQZ 二.安装 点击下一步: 老规矩,打勾,下一步: 这里我们新建一个文件夹 VM12 最好放在D盘或者 ...
- Asp.Net Mvc项目添加WebApi
1.添加一个WebApi 空项目 2.删除WebApi项目下的 Global.asax 文件,因为我们要把WebApi项目整合到Mvc项目中去,全局只需要一个Global 3.修改 WebApi 项目 ...
- C#的@标志的使用情况—本篇blog采用Markdown编写
@(C# 参考--出自官方文档入口) 1.使 C# 关键字用作标识符. @ 字符可作为代码元素的前缀,编译器将把此代码元素解释为标识符而非 C# 关键字. 下面的示例使用 @ 字符定义其在 for 循 ...
- docker 学习1 WSL docker ,Windows docker
获取Linux内核版本 //使用 lsb_release -a 可见我电脑上的 WSL Linux 版本是 Ubuntu的. 安装docker for ubuntu (遇到问题) 转[http://b ...
- XCode下在不同位置声明变量的用法(转)
XCode下在不同位置声明变量的用法 方式一:直接在.h文件@interface中的大括号中声明. @interface Test : NSObject { NSString *str; // 私有变 ...