HDU - 1358 - Period (KMP)】的更多相关文章

Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4325    Accepted Submission(s): 2087 Problem Description For each prefix of a given string S with N characters (each character has an ASCI…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3196    Accepted Submission(s): 1603 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
Problem - 1358 KMP求循环节次数.题意是,给出一个长度为n的字符串,要求求出循环节数大于1的所有前缀.可以直接用KMP的方法判断是否有完整的k个循环节,同时计算出当前前缀的循环节的个数. 代码如下: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ; char buf[N]; int next[…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2398    Accepted Submission(s): 1187 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
Period Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 53   Accepted Submission(s) : 27 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description For each prefix of a given str…
思路: 这里只要注意一点,就是失配值和前后缀匹配值的区别,不懂的可以看看这里,这题因为对子串也要判定,所以用前后缀匹配值,其他的按照最小循环节做 代码: #include<iostream> #include<algorithm> const int N = 1000000+5; const int INF = 0x3f3f3f3f; using namespace std; int fail[N]; char p[N]; void getFail(){ fail[0] = -1;…
题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; #define MaxSize 1000005 char str[MaxSize]; int next2[MaxSize]; void GetNext(char t[]){ int j,k,len; j=; k=-; next2[]=-; len=strl…
Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4437    Accepted Submission(s): 2145 Problem Description For each prefix of a given string S with N characters (each character has an ASCII…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #include <cstdio> #include <cstring> using namespace std; ],sum,lens,lenc; ],ch[]; int get_next() { ,j=-; next[]=-; while (i<strlen(str)) { ||…
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是KMP. #include <string.h> #include <stdio.h> #include <iostream> using namespace std ; ; char ch[maxn] ; int next[maxn] ; int main() { int…
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s'affirmait faux. Tout avait Fair…
题意:主串中能找到几个模式串 思路:超详细解释KMP KMP:针对这个代码,解释一下Fail数组的含义:T为主串,P为模式串,Fail代表失配值,即当P[j] != T[i]时,j要指向的位置为Fail[j],当Fail为-1时表示i指针后移.如果使用这个代码,Fail[j]的值的含义为P[0]…P[j-1]这个子串的前后缀匹配度,但是下面代码的不是!!! 代码: #include<iostream> #include<algorithm> const int N = 100000…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can mo…
 physics(物理) Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Description 题目描述 There are n balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be considered…
 Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each ki…
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were trapped in a…
HDU 5976 Detachment(拆分) 00 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 In a highly developed alien society, the habitats are almost infinite dimensional space. In the history of this planet,there is an o…
poj2406 Power Strings(kmp) 给出一个字符串,问这个字符串是一个字符串重复几次.要求最大化重复次数. 若当前字符串为S,用kmp匹配'\0'+S和S即可. #include <cstdio> #include <cstring> using namespace std; const int maxn=2e6+5; char s1[maxn], s2[maxn]; int n1, n2, nxt[maxn], ans; int main(){ while (~…
<题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第四行aabaabaab可由三个aab组成: 第五行aabaabaabaab可有四个aab组成 解题分析: 求字符串的前缀是否为周期串,若是,打印循环节的长度及循环次数: #include <cstdio> #include <cstring> ; char s[M]; int nxt[…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一串字符串,判断字符串的前缀是否由某些字符串多次重复而构成. 也就是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第四行aabaabaab可由三个aab组成: 第五行aabaabaabaab可由四个aab组成. 解题思路:同HDU 3746类似,通过计算字符串前缀的循环节获…
Description “Be subtle! Be subtle! And use your spies for every kind of business. ”― Sun Tzu“A spy with insufficient ability really sucks”― An anonymous general who lost the warYou, a general, following Sun Tzu’s instruction, make heavy use of spies…
链接  HDU 1711 Number Sequence KMP 算法 我以自己理解写的,写的不对,不明白的地方海王子出来,一起共同学习: 字符串匹配 就是KMP,一般思想,用一个for循环找开头   如果开头一样进入第二个for循环:这样统计  直观 容易理解.但是时间复杂度比较长.所以就有KMP  这个算法了 KMP 大体思想因为在上一个方法之中,有的字符重复比较了,使得找到目标字符窜效率比较低, 比如   :目标串为:   ① a b a b c 在                 ② a…
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative inte…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:给出n个正整数(数组A).每次随机选出三个数.问这三个数能组成三角形的概率为多大? 思路:求出有多少种选择的方案,除以总选择方案即可.用num[i]表示长度为i的出现几次. 对于样例1 3 3 4,我们得到num={0,1,0,2,1}, 对num求卷积,得到:num={0,0,1,0,4,2,4,4,1}.此时的num[i]表示选择两个数和为i的选择方案的种数. 但是这里有重复的: (…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少次后使得最后n次的面完全不同? 思路:设dp[i]表示i次完全相同.不同时还需要抛的次数期望. (1)下面首先讨论完全相同的情况. (2)完全不同的情况: i64 Pow(int n,int m){    i64 ans=1,x=n;    while(m)    {        if(m&1)…
http://acm.hdu.edu.cn/showproblem.php?pid=1236 Problem Description 今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑 每题的分值,所以并不是最后的排名.给定录取分数线,请你写程序找出最后通过分数线的 考生,并将他们的成绩按降序打印.    Input 测试输入包含若干场考试的信息.每场考试信息的第1行给出考生人数N ( 0 < N < 1000 ).考题数M ( 0 < M <…
题意 给定一个字符串 \(S\) ,一次操作可以在这个字符串的右边增加任意一个字符.求操作之后的最短字符串,满足操作结束后的字符串是回文. \(1 \leq |S| \leq 10^6\) 思路 \(\text{KMP}\) 的 \(fail\) 数组是整个算法最重要的东西,能拓展出很多东西. 对于一个模式串(pattern)\(P\) ,\(fail\) 数组为 \(f\) ,那么 \(f[i]\) 就是如果匹配到 \(i\) 这个位置失配,下次去尝试的位置,也就说明了从字符串头到 \(f[i…