HDU 5371 Hotaru's problem
来源:互联网 发布:批量发送工资条软件 编辑:程序博客网 时间:2024/05/20 09:48
http://acm.hdu.edu.cn/showproblem.php?pid=5371
先跑一次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;}
0 0
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- hdu 5371 Hotaru's problem
- HDU 5371 Hotaru's problem
- HDU 5371 - Hotaru's problem(Manacher算法)
- hdu 5371 Hotaru's problem (Manacher算法)
- hdu 5371 Hotaru's problem(manachar)
- hdu 5371 Hotaru's problem【manacher】
- hdu 5371 Hotaru's problem (Manacher算法)
- HDU 5371 Hotaru's problem Manacher+Set
- HDU 5371 Hotaru's problem(Manacher)
- [HDU 5371]Hotaru's problem:Manacher
- 【HDOJ 5371】 Hotaru's problem
- HDU 5371 Hotaru's problem (Manacher+暴力)
- HDU 5371 Hotaru's problem Manacher + set维护
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
- 吃一堑 长一智
- cordova数据请求
- sqoop-1.99.6安装和测试
- 理解Cookie和Session机制
- C语言操作符优先级
- HDU 5371 Hotaru's problem
- 动态规划问题(2)-最长上升子序列
- json格式null转空串
- Android开发----AsyncTask的使用以及源码解析
- opencv森林火灾检测-2
- 7.正则表达式(可用于在抓取的html源码中,获取要求的数字)
- HTML5中<video>标签的duration属性在IE中为NAN的原因
- Android —— 解决MVP引起的内存泄漏
- 漫步微积分十七——最大最小值问题(续)