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( ...
随机推荐
- C++Primer 5th Chap6 Functions
局部静态变量,关键字static修饰,即使函数结束执行也不受影响,生存期直到程序终止. java中static的单一存储空间的概念与其或有异曲同工之妙. 函数的形参可以无名,但有名可以使其意义更加清晰 ...
- 删除列表的三个方式(python)
del是个语句而不是方法 del member[1]:通过下标进行删除 del member:也可删除整个列表 remove():根据列表元素本身来删除,而不是通过下标 member.remove(' ...
- gin PostForm 方法不起作用
情景: 在httpie post 下,在 axios post下,总的来说,就是在form-data下只有c.Bind()会有用 如果一定要用c.PostForm() headers必须为x-www- ...
- 【计算几何】The Queen’s Super-circular Patio
The Queen’s Super-circular Patio 题目描述 The queen wishes to build a patio paved with of a circular cen ...
- s5p6818 从SD卡启动程序(制作SD启动卡)
背景: 最近在学习uboot,其中有一步很重要的任务就是需要实现uboot 的验证,没有办法验证uboot是不是自己做的,那么整个开发就会收到阻碍.另外,从公司现在开发的板子来看,uboot从sd卡启 ...
- Thread 如何安全结束一个线程 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- java基础知识学习 内存相关
Java 内存分配策略 静态存储区(方法区):主要存放静态数据.全局 static 数据和常量.这块内存在程序编译时就已经分配好,并且在程序整个运行期间都存在. 栈区 :当方法被执行时,方法体内的局部 ...
- Java QuickSort 快速排序
Java QuickSort /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternational ...
- java 框架-模板引擎FreeMarker
https://www.cnblogs.com/itdragon/p/7750903.html FreeMarker是一个很值得去学习的模版引擎.它是基于模板文件生成其他文本的通用工具.本章内容通过如 ...
- 货币转换C
描述 人民币和美元是世界上通用的两种货币之一,写一个程序进行货币间币值转换,其中: ...