原题链接

题目大意:

给出一串由'R', 'G', 'B'组成的长度为n的字符串,在里面选出一个长度为k的子串,要求在改变最少字符的情况下同时也是"RGBRGBRGB…"的子串。

思路:
简单版本测试数据范围小,可以直接暴力。

有三种匹配情况(分别以'R', 'G', 'B'开始),如果不匹配则改变次数+1,每次匹配完都更新一次最小值。

代码:

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int q, n, k, mmin;
  6. ] = {'R', 'G', 'B'};
  7. ];
  8.  
  9. int My_Min(int a, int b)
  10. {
  11. return a>b?b:a;
  12. }
  13.  
  14. int main()
  15. {
  16. cin >> q;
  17.  
  18. ; i <= q; i++)
  19. {
  20. cin >> n >> k;
  21. mmin = ;
  22. ; j <= n; j++)
  23. {
  24. cin >> s[j];
  25. }
  26.  
  27. ; j <= n-k+; j++)
  28. {
  29. ] = {};
  30. ; t < k; t++)
  31. {
  32. ])
  33. {
  34. num[]++;
  35. }
  36. )%])
  37. {
  38. num[]++;
  39. }
  40. )%])
  41. {
  42. num[]++;
  43. }
  44. }
  45. mmin = My_Min(My_Min(mmin, num[]), My_Min(num[], num[]));
  46. }
  47. cout << mmin << endl;
  48. }
  49. ;
  50. }

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. rancher部署K8S

    环境:centos7 docker 日期准确 关闭防火墙 安装docker 创建 vim /etc/docker/daemon.json {    "registry-mirrors&quo ...

  2. 洛谷 - P3803 - 【模板】多项式乘法(FFT) - FFT

    https://www.luogu.org/problemnew/show/P3803 用反向学习的FFT通过这个东西. #include <bits/stdc++.h> using na ...

  3. 记录混合APP开发遇到的坑!!

    1.在IOS中给body绑定click事件会失效 2.在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是 ...

  4. JS-04 JS中的函数都是按值传递的

    JS中的函数都是按值传递的 1.传递参数是基本类型 如例子:基本类型传入函数后,函数内部参数生成一个参数副本,把num变量的值赋给num参数,num参数再去参与函数中的运算,但不会影响外面num变量的 ...

  5. ECMAScript严格模式

    ECMAScript 第5个版本 1. 严格模式: 什么是: 比普通js运行机制,要求更严格的模式 为什么: js语言本身具有很多广受诟病的缺陷 何时: 今后所有的js程序,必须运行在严格模式下! 如 ...

  6. Java JNA (一)—— 调用dll

    Java调用C++动态链接库的方式很多,有jnative,jna等.这里介绍如何通过jna的方式调用动态链接库. 调用代码很简单,就是需要注意几个问题. 补充:如dll内部访问配置文件,需将配置文件放 ...

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

  8. shell函数的结束与返回值

  9. Android】Retrofit网络请求参数注解,@Path、@Query、@QueryMap...(转)

    对Retrofit已经使用了一点时间了,是时候归纳一下各种网络请求的service了. 下面分为GET.POST.DELETE还有PUT的请求,说明@Path.@Query.@QueryMap.@Bo ...

  10. Vue 侦听属性

    Vue 提供了一种更通用的方式来观察和响应 Vue 实例上的数据变动:侦听属性 <!DOCTYPE html> <html> <head> <meta cha ...