hdu4763Theme Section

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763

nex。

 1 /*
 2 #include<cstdio>
 3 #include<cstring>
 4 const int maxn=1e6+10;
 5 char s[maxn];
 6 int v[maxn];
 7 
 8 int main()
 9 {
10     int t;
11     scanf("%d",&t);
12     while(t--)
13     {
14         int cnt=0;
15         scanf("%s",s);
16         int n=0;
17         int len=strlen(s);
18         for(int i=0;i<len;i++)
19             if(s[i]==s[0]) v[n++]=i;
20         for(int i=0;i<n;i++)
21             for(int j=i+1;j<n;j++)
22         if(v[j]-v[i]>1) {
23             cnt++;
24             i=j;
25             break;
26         }
27         printf("%d\n",cnt);
28     }
29 }
30 */
31 //ртио╤а╢МлБак-_-||
32 #include<cstdio>
33 #include<cstring>
34 const int maxn=1e6+10;
35 char s[maxn];
36 int nex[maxn];
37 int n;
38 int main()
39 {
40     int t;
41     scanf("%d",&t);
42     while(t--)
43     {
44         scanf("%s",s);
45         n=strlen(s);
46         int i=0,j=-1;
47         nex[0]=-1;
48         while(i<n)
49         {
50             if(j==-1||s[i]==s[j])
51                 nex[++i]=++j;
52             else j=nex[j];
53         }
54         if(nex[n]*2>n) printf("%d\n",n/2);
55         else printf("%d\n",nex[n]);
56     }
57 }

 

转载于:https://www.cnblogs.com/yijiull/p/6614067.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值