CF1209B Koala and Lights
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.
The first line contains a single integer n (1≤n≤100), the number of lights.
The next line contains a string s of n characters. The ii-th character is "1", if the i-th lamp is initially on. Otherwise, i-th character is "0".
The i-th of the following n lines contains two integers ai and bi (1≤ai,bi≤5) — the parameters of the i-th light.
Print a single integer — the maximum number of lights that will ever be on at the same time.
3
101
3 3
3 2
3 1
2
4
1111
3 4
5 2
3 1
3 2
4
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
6
For first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).
In the second example, all lights are initially on. So the answer is 4.
解释题意:有n盏灯,1代表开0代表关,初始状态已给出,每盏灯有a和b两个属性,bs之后灯切换一次状态,之后每a秒切换一次状态。求最多同时亮几盏灯。
不难想到我们可以模拟所有的状态而所有状态的周期最多是2*3*4*5+5种。保险起见可以多跑几次
#include <bits/stdc++.h>
using namespace std;
bool a[];
int l[];
int r[];
int c[];
int f[];
int main()
{
int n;
cin>>n;
string str;
cin>>str;
for(int i=;i<str.size();++i)
{
if(str[i]=='')
{
a[i+]=;
}
else
{
a[i+]=;
}
}
for(int i=;i<=n;++i)
{
cin>>l[i]>>r[i];
c[i]=l[i];
}
int mmax=;
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int k=;k<=;++k)
{
int tmp=;
for(int i=;i<=n;++i)
{
if(a[i]==)
{
tmp++;
mmax=max(mmax,tmp);
}
}
for(int i=;i<=n;++i)
{
if(f[i]==&&r[i]==)
{
c[i]--;
if(c[i]==)
{
c[i]=l[i];
a[i]=!a[i];
}
}
if(r[i]>)
{
r[i]--;
if(r[i]==)
{
a[i]=!a[i];
f[i]=;
}
}
}
}
cout<<mmax;
return ;
}
CF1209B Koala and Lights的更多相关文章
- Codeforces Round #584 B. Koala and Lights
链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...
- 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< ...
- jQuery可自动播放动画焦点图插件Koala
Koala是一款简单而实用的jQuery焦点图幻灯片插件,焦点图不仅可以在播放图片的时候让图片有淡入淡出的动画效果,而且图片可以自动播放.该jQuery焦点图的每一张图片都可以设置文字描述,并浮动在图 ...
- Sass:初识Sass与Koala工具的使用
一.下载Koala(找到合适的系统版本)并安装 二.先新建一个css文件夹,并在里面新建一个文本文档(.txt),将其命名为demo.scss 三.打开Koala,将css文件夹拽进来,可以修改一下输 ...
- koala预编译工具的使用
Koala是一个开源的预处理语言图形编译工具,目前已支持Less.Sass.Compass与CoffeeScript. 安装Koala 在Koala官网根据你的系统平台下载对应的版本.Linux系统要 ...
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- Ubuntu下安装Koala
1.下载koala ,官方网址 目前官方链接的到百度云上的包好像有问题,不能安装,这里分享下 https://yunpan.cn/ckAF4L3TR4kKG (提取码:179a) 2.执行 $ sud ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...
随机推荐
- Linux中用systemctl命令管理服务
systemctl start foo.service 启动服务systemctl restart foo.service 重启服务systemctl stop foo.service 停止服务sys ...
- [经验] Cocos Creator使用笔记 --- 调用不同脚本下的函数
因为 JavaScript 不同于 Java, 想要调用不同文件的函数的话不能直接 ClassName object = new ClassName(); object.function(param) ...
- idea中如何将一个普通项目转换为maven项目
在pom.xml 文件上右键 Add as Maven Project即可.
- 利用Docker构建开发环境
最近接触PAAS相关的知识,在研发过程中开始使用Docker搭建了自己完整的开发环境,感觉生活在PAAS时代的程序员真是幸福,本文会简要介绍下Docker是什么,如何利用Docker来搭建自己的开发环 ...
- Unity Scene视图下 输出物体坐标等信息
using UnityEditor; using UnityEngine; [CustomEditor(typeof(GameObject))] public class MyEditor : Edi ...
- mysql 索引优化法则
建表语句 CREATE TABLE staffs( id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR (24) NOT NULL DEFAULT '' C ...
- js学习(四)
一.typeof 操作符,null, undefinde 1. typeof 操作符来检测变量的数据类型. typeof "John" // 返回 string typeof 3. ...
- oracle 实现主键id自增
公司现在项目数据库使用oracle,oracle实现表主键自增比mysql麻烦 mysql 在表主键auto_increment 打钩即可.oracle没有改属性,就相对麻烦.特此记录一下自增方法 测 ...
- HTML速写
1. E 代表HTML标签. 2. E#id 代表id属性. 3. E.class 代表class属性. 4. E[attr=foo] 代表某一个特定属性. 5. E{foo} 代表标签包含的内容是f ...
- tools.sublime.ConvertToUTF8
sublime乱码,GBK乱码,安装插件ConvertToUTF8 下载ConvertToUTF8,解压,文件夹命名为ConvertToUTF8 sublime->Preferences-> ...