标签:return tps 循环 uri name 无线传输 ++ ctime include
题面:https://www.luogu.org/problemnew/show/P4391
本题中n-next[n]即为字符串最小长度的循环节。
Code:
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<ctime>
using namespace std;
const int N=1000005;
int n,nxt[N];
char ss[N];
int main(){
scanf("%d%s",&n,ss+1);
int j=0;
for(int i=2;i<=n;++i){
if(j&&ss[i]!=ss[j+1]) j=nxt[j];
if(ss[i]==ss[j+1]) ++j;
nxt[i]=j;
}
printf("%d",n-nxt[n]);
return 0;
}
标签:return tps 循环 uri name 无线传输 ++ ctime include
原文地址:https://www.cnblogs.com/ukcxrtjr/p/11195048.html