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

hdu3294Girls' research(manacher)

时间:2017-03-25 00:44:50      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:链接   blank   clu   return   href   tchar   ace   manacher   eof   

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

题目不难,感觉输出比较麻烦。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=2000010;
 6 char s[maxn<<1];
 7 int r[maxn<<1];
 8 char ans[maxn];
 9 char ch;
10 int main()
11 {
12     while(scanf("%c",&ch)!=EOF)
13     {
14         getchar();
15         scanf("%s",s);
16         getchar();
17         int z=a-ch;
18         int id=0,m=0,mx=0;
19         int len=strlen(s);
20         for(int i=len;i>=0;i--)
21         {
22             s[2*i+2]=s[i];
23             s[2*i+1]=#;
24         }
25         s[0]=*;
26         for(int i=2;i<2*len+1;i++)
27         {
28             if(id+r[id]>i) r[i]=min(r[2*id-i],r[id]+id-i);
29             else r[i]=1;
30             while(s[i-r[i]]==s[i+r[i]]) r[i]++;
31             if(m<r[i]) {m=r[i];mx=i;}
32             if(id+r[id]<i+r[i]) id=i;
33 
34         }
35         m--;
36         int sx=-1,e=-1;
37         if(m<=1) puts("No solution!");
38         else  
39             {
40 
41                 int po=0;
42                 for(int i=mx-m;i<=mx+m;i++)
43                 {
44                     if(s[i]!=#&&s[i]!=*) 
45                     {
46                         if(sx==-1&&e==-1) {sx=i;e=i;}
47                         e=i;
48                         ans[po++]=char(s[i]-a+z+26)%26+a;
49 
50                     }
51                 }
52             ans[po]=\0;
53             printf("%d %d\n%s\n",sx/2==0?0:sx/2-1,e/2-1,ans);
54             }
55     }
56     return 0;
57 }

 

hdu3294Girls' research(manacher)

标签:链接   blank   clu   return   href   tchar   ace   manacher   eof   

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

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