一、题目

  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. ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全的问题

    ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全,如下图: 面的绘制代码如下: public void Draw(Display dis, Pen p1, Pen p2,Pen p3 , ...

  2. iTerm2终端工具在Mac OS上使用详解

    一.概述 因个人工作需要,使用终端工具进行运维和开发工作,但是Mac OS 自带的终端工具使用堡垒机登录配置不了,而且使用CRT等终端工具每次登录堡垒机都需要配置密码,操作起来很麻烦.一直想找一款终端 ...

  3. Netty(五)Netty 高性能之道

    4.背景介绍 4.1.1 Netty 惊人的性能数据 通过使用 Netty(NIO 框架)相比于传统基于 Java 序列化+BIO(同步阻塞 IO)的通信框架,性能提升了 8 倍多.事 实上,我对这个 ...

  4. Spring(二) Mini版Spring的实现

    实现思路 先来介绍一下 Mini 版本的 Spring 基本实现思路,如下图所示: 自定义配置 配置 application.properties 文件 为了解析方便,我们用 application. ...

  5. js sort tricks All In One

    js sort tricks All In One js 排序技巧 const arr = [ { label: 'False 1 ', disabled: false, }, { label: 'F ...

  6. 你不知道的 JS (系列丛书) - 第二版

    你不知道的 JS (系列丛书) - 第二版 You Don't Know JS (book series) - 2nd Edition https://github.com/learning-js-b ...

  7. Java REPL & JShell

    Java REPL & JShell Java 11 JShell Java Shell https://www.infoq.com/articles/jshell-java-repl/ Th ...

  8. git cli all in one

    git cli all in one https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud git create ...

  9. Travis CI in Action

    Travis CI in Action node.js https://docs.travis-ci.com/user/tutorial/ https://docs.travis-ci.com/use ...

  10. ORM & sequelize

    ORM Object Relational Mapping 对象关系映射 Table => Object, 简化 SQL 查询命令的编写 https://en.wikipedia.org/wik ...