【题解】Rusty String [CF827E]】的更多相关文章

[题解]Rusty String [CF827E] 传送门:\(\text{Rusty String}\) \(\text{[CF827E]}\) [题目描述] 多组数据,每组数据给出一个由 \(V,K,?\) 三种字符组成的字符串,其中 \(?\) 可以替换为 \(V,K\) 中的任意一个,求替换后的字符串可以存在的循环周期有哪些. [分析] 乍一看像是带通配符的字符串匹配(不会的强烈建议去康康这个),由于字符集不大,按照套路就应该枚举两个字符 \(a \ne b\in\{V,K\}\),然后…
[CF827E]Rusty String 题意:给你一个01串,其中部分字符是'?',?可以是0或1,求所有可能的d,满足存在一种可能得到的01串,在向右移动d格后与自己相同. $n\le 5\times 10^5$ 题解:我们先枚举d,那么一个串符合条件当且仅当:$\forall i \in [0,d), a_i=a_{i+d}=a_{i+2d}=...$,我们可以用fft来判断是否相等.具体地,我们令a串代表正串中的V,b串代表反串中的K,求a和b的卷积c,这样只需要判断$c_d,c_{2d…
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was…
E. Rusty String time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" a…
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm> using namespace std; /* 水题,注意字符范围是整个ASCII编码即可. */ ; int vis[maxn]; +]; +]; int main() { gets(s1); //getchar(); gets(s2); int len1=strlen(s1); int len2=s…
传送门 如果没有碍事的?的话,判定字符串的循环节直接用KMP的失配数组就可以搞定.现在有了碍事的?,我们就需要考虑更通用的算法. 考虑KMP失配数组判定字符串循环节的本质,发现判定\(k\)是否为字符串的循环节等价于判定字符串在右移\(k\)位后能否和原字符串匹配(只考虑二者重叠的部分). 我们不妨先把?直接看成一个可以匹配任何字符的通配符,而解决带通配符的字符串匹配问题的一个算法就是FFT. (以下默认下标为\(0\)~\(n-1\)) 设字符串为\(s\),因为字符集只有\(2\),不妨直接…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ 008. String to Integer (atoi) [E] 题目 Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cas…
又是一道恶心的简单题. 一开始没想到这么多情况的,幸好LeetCode是个很人性化的oj,能让你知道你在哪个case上错了,否则一辈子都过不了. 考虑不周到只能一个个补了. 列举一下恶心的case //" 010" //" +004500" //" -0012a42" //"2147483648" //" b11228552307" //"18446744073709551617" //…
第八题 class Solution { public: int myAtoi(string str) { ; ; ; while(str[i] == ' ')i++; if (str[i] == '-'|| str[i] == '+') { ; i++; } ') { if(sum>=INT_MAX) break; sum = sum * + str[i++] - '; } sum*=sign; if(sum>=INT_MAX)return INT_MAX; if(sum<=INT_M…
咕了好久没更博客,最近得知可以去冬眠营玩耍,还可以搭顺风车回广州过年 (最近做到的比较有意思的题目:bzoj3958.hihocoder1419) Problem Codeforces-710F--洛谷提交入口 题目概要:维护一个字符串集合,要求支持:加字符串.删字符串和查询当前所有已加入且未被删除的字符串在给出模板串中出现的次数(操作数&字符串总长\(\leq 3\times 10^5\)) Solution 挺有意思的一道题 看到多串匹配就猜测是AC自动机,然后动态加串删串不好处理 就将加入…