题目链接:http://codeforces.com/contest/432/problem/D 题意:对一个长度不超过10^5的字符串.按长度输出和后缀全然匹配的的前缀的长度,及该前缀在整个串中出现的次数.(可重叠) #include <cstdio> #include <cstring> const int N=100005; char str[N]; int next[N],cnt[N],ansp[N],ansn[N],n; void getNext (char s[],in…
                                                    D. Prefixes and Suffixes You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j ≤ |s|)…
D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce s…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud D. Prefixes and Suffixes You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: A substring s[i..j] (1 ≤ i ≤ j…
题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出全部的前后缀串,然后利用dp求解,dp[i]表示从1到i这个子串出现过的次数. 转移方程dp[jump[i]]+=dp[i]. 随意一个dp[i]的初始状态应该是1. #include <cstdio> #include <cstring> const int N = 1e5+5; i…
用扩展KMP做简单省力..... D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.…
题目链接:Prefixes and Suffixes 题意:给定未知字符串长度n,给出2n-2个字符串,其中n-1个为未知字符串的前缀(n-1个字符串长度从1到n-1),另外n-1个为未知字符串的后缀(n-1个字符串长度从1到n-1),判断这2n-2个字符串分别为前缀还是后缀. 题解:从2n-2从找个n-1长度的字符串和1长度的字符串拼接,判断该字符串是否符合要求,能作为未知字符串.符合的话,直接输出答案. #include <set> #include <map> #includ…
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and s…
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i,j)满足l <= i <= j <= r 且 sum[j] - sum[i-1] = k\) 思路: 区间左右端点的挪动对答案的贡献符合加减性质,直接用莫队算法即可 复杂度\(O(n * sqrt(n) * log(maxsum))\) 过高 考虑先离散化预处理出所有位置 将\(log\)去…
手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit per test 1:second memory limit per test: 256 megabytes input: standard input output: standard output You have a string s = s1s2...s|s|, where |s| is…