[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher F
发布时间:2020-12-14 05:09:53 所属栏目:大数据 来源:网络整理
导读:F - The Minimum Length HUST - 1010 题目链接:https://vjudge.net/contest/70325#problem/F 题目: There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it fr
F - The Minimum Length HUST - 1010题目链接:https://vjudge.net/contest/70325#problem/F 题目:
There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then,give you the string B,can you tell me the length of the shortest possible string A.
For example,A="abcdefg". I got abcd efgabcdefgabcdefgabcdefg.... Then I cut the red part: efgabcdefgabcde as string B. From B,you should find out the shortest A. InputMultiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000. OutputFor each line,output an integer,as described above.Sample Input bcabcab efgabcdefgabcdeSample Output 3 7 // // Created by HJYL on 2019/8/15. // #include <iostream> #include <vector> #include <map> #include <string> #include <queue> #include <stack> #include <set> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> using namespace std; const int maxn=1e6+10; char str[maxn]; int nextt[maxn]; void getnext() { int i=0,j=-1; nextt[0]=-1; int n=strlen(str); while(i<n) { if(j==-1||str[i]==str[j]) { i++,j++; if(str[i]!=str[j]) nextt[i]=j; else nextt[i]=nextt[j]; } else j=nextt[j]; } } int main() { //freopen("C:Usersasus567767CLionProjectsuntitledtext","r",stdin); while(~scanf("%s",str)) { getnext(); int len=strlen(str); printf("%dn",len-nextt[len]); } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |