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 ...
随机推荐
- rancher部署K8S
环境:centos7 docker 日期准确 关闭防火墙 安装docker 创建 vim /etc/docker/daemon.json { "registry-mirrors&quo ...
- 洛谷 - P3803 - 【模板】多项式乘法(FFT) - FFT
https://www.luogu.org/problemnew/show/P3803 用反向学习的FFT通过这个东西. #include <bits/stdc++.h> using na ...
- 记录混合APP开发遇到的坑!!
1.在IOS中给body绑定click事件会失效 2.在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是 ...
- JS-04 JS中的函数都是按值传递的
JS中的函数都是按值传递的 1.传递参数是基本类型 如例子:基本类型传入函数后,函数内部参数生成一个参数副本,把num变量的值赋给num参数,num参数再去参与函数中的运算,但不会影响外面num变量的 ...
- ECMAScript严格模式
ECMAScript 第5个版本 1. 严格模式: 什么是: 比普通js运行机制,要求更严格的模式 为什么: js语言本身具有很多广受诟病的缺陷 何时: 今后所有的js程序,必须运行在严格模式下! 如 ...
- Java JNA (一)—— 调用dll
Java调用C++动态链接库的方式很多,有jnative,jna等.这里介绍如何通过jna的方式调用动态链接库. 调用代码很简单,就是需要注意几个问题. 补充:如dll内部访问配置文件,需将配置文件放 ...
- docker-compose启动报错:Creating network "soft_default" with the default driver ERROR: cannot create network e5b60fc347db868e471b61ea185fd24e3ea7e2730149d91ad70baf29732aaff0 (br-e5b60fc347db): conflicts wi
docker-compose启动容器时出现报错 Creating network "soft_default" with the default driver ERROR: can ...
- shell函数的结束与返回值
- Android】Retrofit网络请求参数注解,@Path、@Query、@QueryMap...(转)
对Retrofit已经使用了一点时间了,是时候归纳一下各种网络请求的service了. 下面分为GET.POST.DELETE还有PUT的请求,说明@Path.@Query.@QueryMap.@Bo ...
- Vue 侦听属性
Vue 提供了一种更通用的方式来观察和响应 Vue 实例上的数据变动:侦听属性 <!DOCTYPE html> <html> <head> <meta cha ...