HDU 5371 Hotaru's problem
2016-08-12 16:19
337 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5371
先跑一次Manacher之后开始枚举每个在Manacher中为原字符不出现的那个那个字符,之后从他回文串的另外一头开始,判断另外一个端点的回文串长度是否大于之前的那个回文串 的长度,如果是更新ans为最大的,之后继续扫描
先跑一次Manacher之后开始枚举每个在Manacher中为原字符不出现的那个那个字符,之后从他回文串的另外一头开始,判断另外一个端点的回文串长度是否大于之前的那个回文串 的长度,如果是更新ans为最大的,之后继续扫描
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #define maxs 100015 #define MME(i,j) memset(i,j,sizeof(i)) using namespace std; int p[maxs],a[maxs],Ma[2*maxs]; void Manacher(int *s,int n) { p[0]=p[1]=1; int mx=1,id=1; for(int i=2;i<n;i++){ if(mx>i) p[i]=min(p[2*id-i],mx-i); else p[i]=1; for(;s[i-p[i]]==s[i+p[i]];p[i]++); if(i+p[i]>mx){ id=i; mx=i+p[i]; } } } int main() { int t,n; int times=1; while(~scanf("%d",&t)) { while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); Ma[0]=-2; for(int i=0;i<n;i++) { Ma[2*i+1]=-1; Ma[2*i+2]=a[i]; } Ma[2*n+1]=-1; Ma[2*n+2]=-3; Manacher(Ma,2*n+2); int ans=0; for(int i=1;i<=2*n+1;i+=2) { for(int j=p[i]+i-1;j-i>ans;j-=2) { if(p[j]-1>=j-i) { ans=max(ans,j-i); break; } } } printf("Case #%d: %d\n",times++,ans/2*3); } } return 0; }
相关文章推荐
- java selenium Selenium IDE介绍及用法
- sqoop-1.99.6安装和测试
- HDU 5823 color II(状压DP)
- Makefile经典教程
- 第四章:Linear Models for Classification exercise 10-24
- Android多权限请求
- HP-UX执行脚本报错The specified value exceeds the user's allowable limit;Cannot create the specifie file
- mockito简单教程
- poj 3255 Roadblocks 次短路 spfa 解题报告
- Opencv中的3种线性滤波器
- java项目之——坦克大战 04
- 数据结构整理(二) 树
- Android时间戳转换为标准Datetime(yyyy-MM-dd hh:mm:ss)格式
- h5多图上传
- 【HDU3072】【JZOJ4686】通讯
- 定位 CLLocationManager
- 高德地图AMap_2DMap_V2.9.0_20160525版下,隐藏“高德地图”logo样式
- OJ-----提取不重复整数
- HDU 5093 Battle ships [二分图匹配] [匈牙利算法]
- 事件的三个阶段