原题链接

题目大意:

给出一串由'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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

  3. 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 ...

  4. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】

    一.题目 D2. RGB Substring (hard version) 二.分析 思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了! 然后我按照题解改了个vector初始化 ...

  5. [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)

    题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 “R”. ...

  6. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)

    传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串 ...

  7. Codeforces 1196D2. RGB Substring (hard version)

    传送门 考虑枚举每一个位置作为可能子段的起点,然后对以这个位置为起点的所有情况下的答案取 $min$ 当固定了起点 $i$ 并且固定了起点 $i$ 最终的字符时,答案也固定了 发现对于所有与 $i \ ...

  8. Codeforces 1196D2 RGB Substring (Hard version) 题解

    题面 \(q\) 个询问,每个询问给出一个字符串 \(s\),要你在 \(s\) 中用最小替换得到无穷字符串 RGBRGBRGB... 的长度为定值 \(k\) 的子串. 题解 一眼看过去可能是编辑距 ...

  9. D2. Remove the Substring (hard version)(思维 )

    D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...

随机推荐

  1. [Codeforces 280D]k-Maximum Subsequence Sum(线段树)

    [Codeforces 280D]k-Maximum Subsequence Sum(线段树) 题面 给出一个序列,序列里面的数有正有负,有两种操作 1.单点修改 2.区间查询,在区间中选出至多k个不 ...

  2. 关于plt.imshow()显示彩图问题

    https://blog.csdn.net/cnnmena/article/details/79613531

  3. #python# error:http.client.RemoteDisconnected: Remote end closed connection without response

    添加headers user-agent 网络情况不好的状态下也能出现

  4. python学习第三十天函数的形参,实参及函数文档

    python函数的形参是定义函数def 函数名 小括号里面的变量,实参是调用函数时候的值,函数文档是提供函数功能的开发文档,下面 详细说明系列方法 1,函数的形参 def chan(name): pr ...

  5. 学python2.7简单还是python3.0简单,两者区别

    学python2.7简单还是python3.0简单,谈谈两者区别 1. 使用__future__模块 Python 3.X 引入了一些与Python 2 不兼容的关键字和特性.在Python 2中,可 ...

  6. 73.Largest Rectangle in Histogram(最大矩形)

    Level:   Hard 题目描述: Given n non-negative integers representing the histogram's bar height where the ...

  7. ECharts 图表导出

    Echarts图形是由Javascript亲自在前端网页上绘制的 1.用ECharts配置项手册中的toolbox.feature.saveAsImage toolbox: { show: true, ...

  8. C#设计模式:原型模式(Prototype Pattern)

    一,原型模式:通过将一个原型对象传给那个要发动创建的对象,这个要发动创建的对象通过请求原型对象拷贝它们自己来实施创建.(包含深度克隆和浅克隆) 主要面对的问题是:“某些结构复杂的对象”的创建工作:由于 ...

  9. Js数据去重复,时间更换格式,cookie,localStorage和sessionStorage的使用等通用方法

    一,数组去重复 function unique(arr) { // 遍历arr,把元素分别放入tmp数组(不存在才放) var tmp = new Array(); for (var i in arr ...

  10. JVM(9)之 年轻代收集器

    开发十年,就只剩下这套架构体系了! >>>   继续上一篇博文所讲的,STW即GC时候的停顿时间,他会暂停我们程序中的所有线程.如果STW所用的时间长而且次数多的话,那么我们整个系统 ...