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( ...
随机推荐
- oracle调用函数的方式
--方法1.PLSQL代码块 SQL> set serveroutput onSQL> declare 2 v_sal emp_pl.sal%type; 3 begin 4 v_sal : ...
- (十四)JDBC入门
目录 什么是JDBC 操作JDBC的步骤 DriverManager对象 数据库URL Connection对象 Statement对象 ResultSet对象 常用数据类型转换表 释放资源 SQL注 ...
- Linux下如何查看tomcat是否启动、查看tomcat启动日志
在Linux系统下,重启Tomcat使用命令的操作! 1.首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh ...
- Spring基础篇——DI/IOC和AOP原理初识
DI(Dependency Injection),依赖注入,和我们常听说的另一个概念 IOC(控制反转)其实归根结底实现的功能是相同的,只是同样的功能站在不同的角度来阐述罢了.这里博主就不去过多的辨析 ...
- Effective Java 读书笔记(三):类与接口
1 最小化类和成员的可访问性 (1)封装 封装对组成系统的组件进行解耦,从而允许这些组件独立开发,测试,优化,使用,理解和修改. 封装提高了软件的复用性,因为组件间的耦合度低使得它们不仅在开发环境,而 ...
- 获取类的描述信息 DescriptionAttribute
static void Main(string[] args) { var attrs = typeof(TestClass).GetCustomAttributes(typeof(System.Co ...
- Django对postgresql数据库进行分组聚合查询
action(methods=['GET'], detail=False, url_path='count') def count(self, request): """ ...
- 使用zrender.js绘制体温单(1)
之前公司请外包做了一个体温单使用的zrender.js 但是代码比较复杂维护性比较低再加上自己技术也不行 最近闲下来的时候看了一下zrender的官网慢慢的摸索并读了下之前的代码,感觉实际并不难,就自 ...
- Vue子父组件方法互调
讲干货,不啰嗦,大家在做vue开发过程中经常遇到父组件需要调用子组件方法或者子组件需要调用父组件的方法的情况,现做一下总结,希望对大家有所帮助. 父组件调用子组件方法: 1.设置子组件的ref,父组件 ...
- web服务器端挖矿代码攻击的错误检测及排除
a)挖矿代码简要阐述: 网页中嵌入Javascript, 一旦用户打开该网站,浏览器便会按照脚本的指令变成一个门罗币挖矿机.这一段附加的挖矿代码通常因为大量占用CPU,使用户的计算机变得异常卡顿甚至无 ...