首页 > 其他 > 详细

F - The Minimum Length

时间:2018-10-31 11:10:03      阅读:138      评论:0      收藏:0      [点我收藏+]
技术分享图片
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int len;
char s[1000010];
int net[1000010];
void getnet(){
    memset(net,0,sizeof(net));
    net[0]=-1;
    int k=-1,j=0;
    while(j<len){
        if(k==-1||s[k]==s[j]){
            j++;k++;
            net[j]=k;
        }
        else k=net[k];
    }
}
int main(){
    while(scanf("%s",s)!=EOF){
        len=strlen(s);
        getnet();
        int tmp=len-net[len];
        printf("%d\n",tmp);
    }
}
View Code

 

 

F - The Minimum Length

原文:https://www.cnblogs.com/cangT-Tlan/p/9881781.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!