传送门 考虑枚举每一个位置作为可能子段的起点,然后对以这个位置为起点的所有情况下的答案取 $min$ 当固定了起点 $i$ 并且固定了起点 $i$ 最终的字符时,答案也固定了 发现对于所有与 $i \mod 3$ 相同的位置的字符和 $i$ 位置的字符是一样的 所有 $j \mod 3 = (i+1) \mod 3$位置的字符也都是一样的并且是可以确定的 所有 $j \mod 3 = (i+2) \mod 3$位置的字符也都是一样的并且是确定的 维护 $cnt[0/1/2][0/1/2]$ 表示…
题面 \(q\) 个询问,每个询问给出一个字符串 \(s\),要你在 \(s\) 中用最小替换得到无穷字符串 RGBRGBRGB... 的长度为定值 \(k\) 的子串. 题解 一眼看过去可能是编辑距离什么的,但是仔细看 Hard 下的时间复杂度不允许,然后进行了一波分析... 上图模式串 2 同理. 从上图可以发现,其实就是主串往后移动一位的同时模式串也往后移动一位匹配,同时去掉无用信息即可. 代码 #include<cstdio> #include<climits> #incl…
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string…
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string s consistin…
一.题目 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…
题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 “R”.“G” 或 “B”. 求出更改初始字符串 s 中的最小字符数,以便更改后将有一个长度为 k 的字符串,该字符串是 s 的子字符串,也是无限字符串 “RGBRGBRGB…” 的子字符串 思路: 在无限字符串中有三种子串:“RGB...”,“GBR...”,“BRG...” 在这三种不同情况下,将所求字…
传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串为str)"里面也是一个子串,这个子串的长度是k 可是有可能s字符串中找不到,那么这个时候就可以改变s字符串中某些位置的字母来完成任务.问最少需要改变多少个字母 题解: 主要看暴力的姿势对不对.在上一道的D1上面,我是对s字符串的每一个位置进行'R','G','B'的枚举,因为如果这个子串也是str…
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the length of the string. You are given a string…
D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions is the length of the string. You are given a stri…
D2. Remove the Substring (hard version) 给字符串s,t,保证t为s的子序列,求s删掉最长多长的子串,满足t仍为s的子序列 记录t中每个字母在s中出现的最右的位置, 然后从s开头开始跑 遇到和当前t[j]相同的s[i],j++ 即使得t中相邻两个字符距离最大化 注意j跑完t了,最后一位应该为s的长度 #include<bits/stdc++.h> using namespace std; ]; ]; ]; int main() { scanf("…