码迷,mamicode.com
首页 > 其他好文 > 详细

hdu4763Theme Section

时间:2017-03-25 00:41:30      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:char   bsp   --   print   get   style   max   ref   acm   

题目链接: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 }

 

hdu4763Theme Section

标签:char   bsp   --   print   get   style   max   ref   acm   

原文地址:http://www.cnblogs.com/yijiull/p/6614067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!