hdu4513(manacher)
传送门:吉哥系列故事——完美队形II
题意:求最长回文队伍且队伍由中间向两边递减。
分析:manach算法小应用,在判断回文子串向两边递减时加点限制使回文是由中间向两边递减的。
- #pragma comment(linker,"/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <cmath>
- #include <limits.h>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <cstdlib>
- #include <stack>
- #include <vector>
- #include <set>
- #include <map>
- #define LL long long
- #define mod 1000000007
- #define inf 0x3f3f3f3f
- #define eps 1e-6
- #define N 100010
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define PII pair<int,int>
- using namespace std;
- inline LL read()
- {
- char ch=getchar();LL x=,f=;
- while(ch>''||ch<''){if(ch=='-')f=-;ch=getchar();}
- while(ch<=''&&ch>=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int p[N<<],ans,len,num,mx,id;
- int a[N],c[N<<],n;
- void build()
- {
- n=read();
- for(int i=;i<n;i++)a[i]=read();
- num=;
- c[num++]=-;c[num++]=inf;
- for(int i=;i<n;i++)
- {
- c[num++]=a[i];
- c[num++]=inf;
- }
- c[num]=-;
- }
- void manacher()
- {
- ans=;mx=;
- memset(p,,sizeof(p));
- for(int i=;i<num;i++)
- {
- if(mx>i)p[i]=min(p[*id-i],mx-i);
- else p[i]=;
- while(c[i-p[i]]==c[i+p[i]]&&(c[i-p[i]]==inf||p[i]==||c[i-p[i]]<=c[i-p[i]+]))p[i]++;
- if(p[i]+i>mx)mx=p[i]+i,id=i;
- ans=max(ans,p[i]-);
- }
- }
- int main()
- {
- int T;
- T=read();
- while(T--)
- {
- build();
- manacher();
- printf("%d\n",ans);
- }
- }
hdu4513(manacher)的更多相关文章
- 吉哥系列故事——完美队形II(hdu4513+Manacher)
吉哥系列故事--完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- HDU4513 吉哥系列故事——完美队形II Manacher算法
题目链接:https://vjudge.net/problem/HDU-4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu----(4513)吉哥系列故事——完美队形II(manacher(最长回文串算法))
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- HDU4513吉哥系列故事――完美队形II(manacher算法)
这个比最长回文子串就多了一个条件,就是回文字串(这里相当于人的高度)由两端向中间递增. 才刚刚看了看manacher,在用模板A了一道题后,还没有完全理解manacher,然后就准备把这道题也直接带模 ...
- hdu4513之manacher算法
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- hdu4513完美队形II manacher
吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一个新的队形,新的队形若满足以下三点要 ...
- HDU4513:完美队形II(Manacher)
Description Input Output Sample Input Sample Output Solution 才发现我之前不会证$Manacher$复杂度……QAQ 题意是求最长向 ...
- HDU4513:吉哥系列故事——完美队形II(Manacher)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)To ...
- 【回文串-Manacher】
Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 转:http://blog.sina.com.c ...
随机推荐
- 【Tesseract-OCR】在VS2012环境下调用API方法---注意避免名字冲突
由于在VS2012中使用OpenCV可以得到插件ImageWatch.vsix的支持,查看图像非常方便,所以一直想在VS2012环境下把Tesseract-OCR融合进来,但是这一错误折腾了我好久: ...
- 推荐国内外优秀+免费CDN加速站点及公共cdn加速库
-----------------------------------------------------------------免费CDN加速站点 1.CloudFlare CloudFlare可能 ...
- asp.net2.0安全性(2)--用户个性化设置(2)--转载来自车老师
上一篇我们用Profile.age等方式可以读取用户的年龄和其它的信息,但有的时候我们要查询显示所有用户的信息,但asp.net没有提供查询所有用户信息的功能,我们只能对现有的用户逐一查询其Profi ...
- PHP学习之-1.7 注释
注释 在PHP中也有注释语句:用双斜杠 "//" 来表示.其他语言中 HTML使用 "<!-- -->" ,CSS中使用 "/* ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- TCP与UDP各自特点对比
UDP和TCP是我们最常用的两种通信方式,下面就两者之间的特点做一个对比: 1.UDP主要用在实时性要求高以及对质量相对较弱的地方,如流媒体. 2.TCP既然是面向连接的,那么运行环境必然要求其保证可 ...
- iot 表 主键索引叶子块包含了表所有数据
<pre name="code" class="html">iot表测试: 在create table语句后面使用organization inde ...
- 简单的ajax获取json
一个DBhelper类,用来操作数据库 using System; using System.Collections.Generic; using System.Linq; using System. ...
- Qt4创建工程的几种方法:linux系统
方法一:以Qt Creator 作为IDE 1.启动Qt Creator,并创建一个空项目 2.输入路径和工程名字 3.添加cpp文件 4.添加代码,并且编译执行 5.执行结果 方法二:利用linux ...
- 【翻译】十大要避免的Ext JS开发方法
原文地址:http://www.sencha.com/blog/top-10-ext-js-development-practices-to-avoid/ 作者:Sean Lanktree Sean ...