一、题目

  D2. RGB Substring (hard version)

二、分析

  思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了!

  然后我按照题解改了个vector初始化,就过了!

  以后得谨慎使用memset了。

三、AC代码

 1 #include <bits/stdc++.h>
2
3 using namespace std;
4 #define ll long long
5 #define Min(a,b) (a)>(b)?(b):(a)
6 const int maxn = 2e5 + 13;
7 char S[maxn];
8 char Q[] = "GBR";
9 int n, k;
10
11 int main()
12 {
13 //freopen("input.txt", "r", stdin);
14 int q;
15 scanf("%d", &q);
16 while(q--)
17 {
18 int ans;
19 scanf("%d%d", &n, &k);
20 scanf("%s", S);
21 ans = k;
22 for(int i = 0; i < 3; i++)
23 {
24 vector<int> dp(n);
25 int p = i, j;
26 int res = 0;
27 for(j = 0; j < k; j++)
28 {
29 if(S[j] != Q[p%3])
30 {
31 res++;
32 dp[j] = 1;
33 }
34 p++;
35 }
36 ans = Min(ans, res);
37 for(j; j < n; j++)
38 {
39 if(S[j] != Q[p%3])
40 {
41 res = res - dp[j - k] + 1;
42 dp[j] = 1;
43 }
44 else
45 {
46 res = res - dp[j - k];
47 }
48 ans = Min(ans, res);
49 p++;
50 }
51 }
52 printf("%d\n", ans);
53 }
54 return 0;
55 }

Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】的更多相关文章

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

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

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

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

  3. Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...

  4. 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)

    题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...

  5. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  6. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  7. Codeforces Round #575 (Div. 3)

    本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...

  8. Codeforces Round #575 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...

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

随机推荐

  1. 获取txt编码方式

    在操作txt的时候,有时会出现乱码,这是因为没有使用正确的编码方式来操作txt,我们需要先获取txt的编码方式,再进行读写操作.下面是获取txt编码的方法: /// <summary> / ...

  2. Python_变量作用域与修改

    引用全局变量,不需要golbal声明,修改全局变量,需要使用global声明,特别地,列表.字典等如果只是修改其中元素的值(而不是整体赋值的形式),可以直接使用全局变量,不需要global声明. 参考 ...

  3. oslab oranges 一个操作系统的实现 实验二 认识保护模式

    https://github.com/yyu/osfs00 实验目的: 理解x86架构下的段式内存管理 掌握实模式和保护模式下段式寻址的组织方式. 关键数据结构.代码组织方式 掌握实模式与保护模式的切 ...

  4. Leetcode(8)-字符串转整数

    实现 atoi,将字符串转为整数. 在找到第一个非空字符之前,需要移除掉字符串中的空格字符.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为整数的值 ...

  5. 2020 Web 全栈面经

    2020 Web 全栈面经 1.简历 2. 技术 3. 项目 4. 架构 5. 沟通,协作 6.成长 7. 面试技巧 准备 电话确认,面试流程,五险一金缴纳情况 有无笔试,几轮,面试时间,答复时间 细 ...

  6. css skeleton & web app skeleton

    css skeleton & web app skeleton skeleton https://www.cnblogs.com/xgqfrms/p/10437258.html https:/ ...

  7. useful podcast

    useful podcast front end podcast https://shoptalkshow.com https://stackoverflow.blog/podcast/ SoundC ...

  8. taro render html

    taro render html html = `<h1 style='color: red'>Wallace is way taller than other reporters.< ...

  9. how to recursively all files in a folder with sudo permissions in macOS

    how to recursively all files in a folder with sudo permissions in macOS write bug OK sudo chmod 777 ...

  10. Nestjs 上传文件到七牛云

    $ npm install qiniu import * as url from 'url'; import * as qiniu from 'qiniu'; @Post('upload') @Use ...