hdu2594 KMP】的更多相关文章

2个字符长合并在一起即可.要注意next[n]的值要小于初始的两个字符串的长度; //next[]存的是之前相同的长度. //也是位置,只是s[i]不一定和s[next[i]]相同 //但是i之前的和next[i]之前相同的个数==next[i]; #include<stdio.h> #include<string.h> #define maxn 50010 ],s2[maxn]; ],fs1,fs2,len; void getnext() { int j,k; j=; k=-;…
题意:求最长的a的前缀同时满足是b的后缀,把a,b连在一起,kmp跑一下,迭代next直到长度小于等于a,b长度的最小值为止,即为答案. #pragma comment(linker, "/STACK:10240000,10240000") #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring&g…
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1746 Accepted Submission(s): 637 Problem Description Homer: Marge, I just figured out a way to discover some of the talents…
Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had.Marge: Yeah, what is it?Homer: Take me for example. I want to find out if I have a talent in politics, OK?Marge: OK.Homer: So I take some politician’s name…
题意: 给两个字符串s1,s2,求最长的s1前缀匹配s2后缀的字符串,以及长度 思路: 利用KMP看下最终匹配到了哪个位置:一个是利用常规匹配,另一个是利用next数组的跳转. #include<bits/stdc++.h> using namespace std; const int N=5e4+10; int lens1,lens2,Next[N]; char s1[N],s2[N]; void GetNext() { int i,j; Next[0]=-1; i=0; j=-1; whi…
题目链接:https://vjudge.net/problem/HDU-2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10647    Accepted Submission(s): 3722 Problem Description Homer: Marge, I just f…
题意:      给你两个串,问你s1的前缀和s2的后缀最长公共部分是多少. 思路:      根据KMP的匹配形式,我们求出s1的next,然后用s1去匹配s2,输出当匹配到s2的最后一个的时候的匹配位置就行了. #include<stdio.h> #include<string.h> #define N 50000 + 10 char stra[N] ,strb[N]; int next[N]; void get_next(int m) { int j ,k; j = 0 ,k…
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2798    Accepted Submission(s): 1055 Problem Description Homer: Marge, I just figured out a way to discover some of the…
Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4976    Accepted Submission(s): 1815 Problem Description Homer: Marge, I just figured out a way to discover some of the t…
Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, OK? Marge: OK. Homer: So I take some politician’s…