CodeForce-1196D1-RGB Substring (easy version)
题目大意:
给出一串由'R', 'G', 'B'组成的长度为n的字符串,在里面选出一个长度为k的子串,要求在改变最少字符的情况下同时也是"RGBRGBRGB…"的子串。
思路:
简单版本测试数据范围小,可以直接暴力。
有三种匹配情况(分别以'R', 'G', 'B'开始),如果不匹配则改变次数+1,每次匹配完都更新一次最小值。
代码:
#include <iostream>
using namespace std;
int q, n, k, mmin;
] = {'R', 'G', 'B'};
];
int My_Min(int a, int b)
{
return a>b?b:a;
}
int main()
{
cin >> q;
; i <= q; i++)
{
cin >> n >> k;
mmin = ;
; j <= n; j++)
{
cin >> s[j];
}
; j <= n-k+; j++)
{
] = {};
; t < k; t++)
{
])
{
num[]++;
}
)%])
{
num[]++;
}
)%])
{
num[]++;
}
}
mmin = My_Min(My_Min(mmin, num[]), My_Min(num[], num[]));
}
cout << mmin << endl;
}
;
}
CodeForce-1196D1-RGB Substring (easy version)的更多相关文章
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- CF #579 (Div. 3) D1.Remove the Substring (easy version)
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabyt ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】
一.题目 D2. RGB Substring (hard version) 二.分析 思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了! 然后我按照题解改了个vector初始化 ...
- [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)
题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 “R”. ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)
传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串 ...
- Codeforces 1196D2. RGB Substring (hard version)
传送门 考虑枚举每一个位置作为可能子段的起点,然后对以这个位置为起点的所有情况下的答案取 $min$ 当固定了起点 $i$ 并且固定了起点 $i$ 最终的字符时,答案也固定了 发现对于所有与 $i \ ...
- Codeforces 1196D2 RGB Substring (Hard version) 题解
题面 \(q\) 个询问,每个询问给出一个字符串 \(s\),要你在 \(s\) 中用最小替换得到无穷字符串 RGBRGBRGB... 的长度为定值 \(k\) 的子串. 题解 一眼看过去可能是编辑距 ...
- D2. Remove the Substring (hard version)(思维 )
D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...
随机推荐
- Web Service-第一篇什么是Web Service
1.什么是WebService? WebService是一种跨编程语言和跨操作系统平台的远程调用技术.WebService就是一个应用程序向外界暴露出一个能通过Web进行调用的API,也就是说能用编程 ...
- mysql DATETIME和TIMESTAMP类型
以mysql 5.7.20 为例 一直以来,理解有偏差,作此记录,纠正 一.DATETIME和TIMESTAMP 都有高达微秒(6位)的精度 范围 DATETIME 1000-01-01 00: ...
- org.apache.hadoop.hive.ql.exec.DDLTask. MetaException错误问题
下载 http://www.java2s.com/Code/Jar/m/Downloadmysqlconnectorjavacommercial517binjar.htm 放到lib目录下,删除原本的 ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- Spring bean相关
Spring中指定Bean的作用于的方式 以下四种为例: 单例(默认,可以不用特殊表明) @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) ...
- oracle ALL视图
select * from ALL_ALL_TABLES -- 用户可存取的所有表. select * from ALL_BASE_TABLE_MVIEWS -- 用户可存取的所有物化视 ...
- CSS语法规则
一.At-rule 一种以@开头的声明语句,以分号;结尾.语法规则为: @IDENTIFIER (RULE); . At-rule主要用作表示CSS的行为,参考: https://www.cnblog ...
- 环境管理 pipenv 的 使用
安装 pip3 install pipenv 配置 配置 环境变量 WORKON_HOME , 表示 生成的虚拟环境 文件 的 存放位置 创建虚拟环境 方式一 pipenv --python 3.7 ...
- Elasticsearch单机安装_集群搭建_索引基本操作_Head插件安装与基本操作_ik分词器配置_logstash实现数据同步_教程
一.Elasticsearch单机安装 1.将es安装包传到服务器上 这是安装包 这里我是用的是WinSCP上传工具,上传到/home/plugins文件下. 进入Xshell,验证一下是否上传成功. ...
- weblogic下载
1.网址 https://edelivery.oracle.com/osdc/faces/SoftwareDelivery 2.信息