这题目上学期就看了,不过最近发现可以用马拉车来解,而且还是基本算法。 稍微对回文串成立条件变形一下即可。

 /* 4513 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e5+;
int a[maxn], b[maxn*];
int Len[maxn*]; void init(int n) {
int j = ; b[j++] = -;
b[j++] = ;
rep(i, , n) {
b[j++] = a[i];
b[j++] = ;
}
} void manacher(int m) {
int n = *m+;
int p = , p0 = ;
int lid, rid; rep(i, , n+) {
if (p > i)
Len[i] = min(p-i, Len[*p0-i]);
else
Len[i] = ; while (b[i+Len[i]] == b[i-Len[i]]) {
if (b[i+Len[i]] > ) {
lid = i - Len[i];
rid = i + Len[i];
if (b[lid]>b[lid+] || b[rid]>b[rid-])
break;
}
++Len[i];
} if (i+Len[i] > p) {
p = i + Len[i];
p0 = i;
}
}
} void solve(int n) {
init(n);
manacher(n); int ans = ; n = n*+;
rep(i, , n) {
ans = max(ans, Len[i]);
}
printf("%d\n", ans-);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t;
int n; scanf("%d", &t);
while (t--) {
scanf("%d", &n);
rep(i, , n)
scanf("%d", &a[i]);
solve(n);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】4513 吉哥系列故事——完美队形II的更多相关文章

  1. HDU 4513 吉哥系列故事――完美队形II

    http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...

  2. HDU 4513 吉哥系列故事——完美队形II manacher

    吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...

  3. hdu 4513 吉哥系列故事——完美队形II (manachar算法)

    吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) P ...

  4. HDU 4513 吉哥系列故事――完美队形II(Manacher)

    题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...

  5. HDU 4513 吉哥系列故事——完美队形II(Manacher)

    Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...

  6. HDU 4513 吉哥系列故事——完美队形II (Manacher变形)

    题意:假设有n个人按顺序的身高分别是h[1], h[2] ... h[n],从中挑出一些人形成一个新的队形,新的队形若满足以下要求,则就是新的完美队形:  1.连续的 2.形成回文串 3.从左到中间那 ...

  7. HDU 4513 吉哥系列故事——完美队形II( Manacher变形 )

    链接:传送门 思路:根据完美队形的定义,可以得知,完美队形实质上是 回文串 + 序列出现峰,因为是在回文串中再次增加了一个要求,所以可以对 Manacher 进行改造,改造的部分应该为暴力匹配的循环 ...

  8. Hdu 4513 吉哥系列故事——完美队形II (manacher变形)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4513 题目描述: 打完题目描述了,点开题目,发现题目是中文,orz.jpg.果断又删掉了,习惯真可怕 ...

  9. HDU 4513 吉哥系列故事——完美队形II

    变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减. 其他地方倒是没有什么改动.. //#define LOCAL #include <iostream&g ...

随机推荐

  1. Jquery Table添加行、删除行

    html页面代码 <table id="tblUserInfo"> </table> Js代码 function DealUserInfo(qty){ ) ...

  2. MVC3中使用AuthorizeAttribute特性来完成登陆权限的验证

    以前判断用户是否登录,判断用户Session是否为空,一般会在这个页面写使用: if (HttpContext.Session.IsNewSession) { //todo Login } 每个需要验 ...

  3. 网站部署后,ie不能显示本地的图片

    html:<div id="imgPreview"  style='width:144px; height:80px;'>                        ...

  4. onMouseDown onMouseUp onMouseMove(移动鼠标图像大小变化)

  5. js 获取时间对象代码

    /** * 获取时间对象 */function getDateObj(addDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+addDa ...

  6. Cogs 1844. [JSOI2008]最大数maxnumber

    [JSOI2008]最大数maxnumber ★★ 输入文件:bzoj_1012.in 输出文件:bzoj_1012.out 简单对比 时间限制:3 s 内存限制:162 MB [题目描述] 现在请求 ...

  7. C++模板学习随笔

    本文学习内容参考:http://www.cnblogs.com/gw811/archive/2012/10/25/2738929.html C++模板 1.模板分为函数模板和类模板两种类型 函数模板针 ...

  8. ASP.NET中Json的处理

    要使用.NET自带的JSON处理工具需要引用下面的命名空间: using System.Web.Script.Serialization; 1.编码 myConfig mc = new myConfi ...

  9. 使用NPOI操作Excel

    案例:用NPOI动态生成一个Excel表,然后弹出对话框让用户下载,文件名是"用户列表.xls" 先去相关网站下载 NPOI DLL文件,再引用   application/x-e ...

  10. phpredis

    安装php的redis扩展: http://pecl.php.net/package/redis 也可以用PHP直接连redis: http://www.cnblogs.com/kudosharry/ ...