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

hdu4513吉哥系列故事——完美队形II(manacher)

时间:2017-03-25 00:52:28      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:code   int   scanf   clu   algo   nbsp   scan   ble   span   

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

manacher。稍微多了一点限制,延伸时要特殊处理一下。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=200010;
 6 int s[maxn<<1];
 7 int r[maxn<<1];
 8 
 9 int main()
10 {
11     int t;
12     scanf("%d",&t);
13     while(t--)
14     {
15         int n;
16         scanf("%d",&n);
17             for(int i=0;i<n;i++)
18                 scanf("%d",&s[i]);
19             for(int i=n;i>=0;i--)
20                 {
21                 s[i*2+2]=s[i];
22                 s[i*2+1]=-1;
23                 }
24             s[0]=-2;
25             s[n*2+2]=-3;
26     int id=0,m=0;
27     for(int i=2;i<2*n+1;i++)
28     {
29         if(id+r[id]>i) r[i]=min(r[id*2-i],r[id]+id-i);
30         else r[i]=1;
31         while(s[i-r[i]]==s[i+r[i]]&&(s[i-r[i]]<=s[i-r[i]+2]||s[i-r[i]]==-1)) r[i]++;  //题目要求对称中心左侧高度不减。
32         if(id+r[id]<i+r[i]) id=i;
33         if(m<r[id]) m=r[id];
34     }
35     printf("%d\n",m-1);
36     }
37 }

 

hdu4513吉哥系列故事——完美队形II(manacher)

标签:code   int   scanf   clu   algo   nbsp   scan   ble   span   

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

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