HDU 4513 单增回文 manacher
2016-07-12 20:49
190 查看
跑manacher的同时判断有序就行了
回文串题目不是很多敲的很少所以敲的时候要仔细别出Bug
回文串题目不是很多敲的很少所以敲的时候要仔细别出Bug
#include<cstring> #include<cstdio> #include<map> #include<string> #include<algorithm> #include<iostream> using namespace std; int a[100010],s1[201111],p[201111],n; int manacher() { int ans = 0; for(int i=1;i<=n;i++) { s1[i*2-1] = -1; s1[i*2] = a[i]; } s1[0] = -2; s1[n*2+1] = -1; s1[n*2+2] = -3; int Max = 0,MaxId = 0; for(int i=1;i<=2*n+1;i++) { p[i] = i>=Max?1:min(p[2*MaxId-i],Max-i); while(s1[i+p[i]]==s1[i-p[i]]&&(s1[i-p[i]]<0||s1[i-p[i]]<=s1[i-p[i]+2]))p[i]++; if(i+p[i]>Max) { MaxId = i; Max = i+p[i]; } ans = max(p[i]-1,ans); } return ans; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); printf("%d\n",manacher()); } return 0; }
相关文章推荐
- 【华为OJ】字符串加密
- 简单HTML的使用
- 链接地址
- as follows ,as follow && following
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4
- Mybatis3.2+版本 log4j2 Debug 模式打印sql语句
- Fibonacci sequence
- CodeForces 374A Inna and Pink Pony
- 通过simpleXML解析XML格式的数据 (两种方法)
- Redis常用几种数据类型
- 实际应用中带头节点的线性链表
- MongoDB实战优化
- noip 2013 提高组 Day2 部分题解
- C - L1(大数比较)
- leetcode368. Largest Divisible Subset
- ToastUtil,一个阻止重复吐司并可控制位置的工具类
- Wildcard Matching
- http://www.cnbc.com/2016/07/12/tensions-in-south-china-sea-to-persist-even-after-court-ruling.html
- http://www.cnbc.com/2016/07/12/tensions-in-south-china-sea-to-persist-even-after-court-ruling.html
- nginx+keepalived构建高可用服务