【BZOJ2342】双倍回文(manacher,并查集)
题意:

思路:From http://blog.sina.com.cn/s/blog_8d5d2f04010196bh.html
var f,p:array[..]of longint;
a:array[..]of char;
len,i,n,mx,id,ans,j:longint;
ch:ansistring; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; function max(x,y:longint):longint;
begin
if x>y then exit(x);
exit(y);
end; function find(k:longint):longint;
begin
if f[k]<>k then f[k]:=find(f[k]);
find:=f[k];
end; begin
assign(input,'bzoj2342.in'); reset(input);
assign(output,'bzoj2342.out'); rewrite(output);
readln(len);
readln(ch);
n:=; a[]:='@'; a[]:='#';
for i:= to len do
begin
inc(n); a[n]:=ch[i];
inc(n); a[n]:='#';
end;
inc(n); a[n]:='$';
mx:=; id:=;
for i:= to n- do
begin
if mx>i then p[i]:=min(p[id*-i],mx-i)
else p[i]:=;
while a[i-p[i]]=a[i+p[i]] do inc(p[i]);
if p[i]+i>mx then
begin
mx:=p[i]+i;
id:=i;
end;
end;
for i:= to n- do
if a[i]='#' then f[i]:=i
else f[i]:=i+;
i:=; j:=;
repeat
i:=i+;
if i>n then break;
j:=find(max(i-p[i] div ,));
while (j<i)and(j+p[j]<i) do
begin
f[j]:=find(j+);
j:=f[j];
end;
if j<i then ans:=max(ans,(i-j)*);
until i>n;
writeln(ans);
close(input);
close(output);
end.
【BZOJ2342】双倍回文(manacher,并查集)的更多相关文章
- 【BZOJ-2342】双倍回文 Manacher + 并查集
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1799 Solved: 671[Submit][Statu ...
- 【做题】BZOJ2342 双倍回文——马拉车&并查集
题意:有一个长度为\(n\)的字符串,求它最长的子串\(s\)满足\(s\)是长度为4的倍数的回文串,且它的前半部分和后半部分都是回文串. \(n \leq 5 \times 10^5\) 首先,显然 ...
- BZOJ2342:[SHOI2011]双倍回文(Manacher)
Description Input 输入分为两行,第一行为一个整数,表示字符串的长度,第二行有个连续的小写的英文字符,表示字符串的内容. Output 输出文件只有一行,即:输入数据中字符串的最长 ...
- [SHOI2011]双倍回文 manacher
题面: 洛谷:[SHOI2011]双倍回文‘ 题解: 首先有一个性质,本质不同的回文串最多O(n)个. 所以我们可以对于每个i,求出以这个i为结尾的最长回文串,然后以此作为长串,并判断把这个长串从中间 ...
- bzoj 2342: [Shoi2011]双倍回文 -- manacher
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...
- [BZOJ2341][Shoi2011]双倍回文 manacher+std::set
题目链接 发现双倍回文串一定是中心是#的回文串. 所以考虑枚举#点.发现以\(i\)为中心的双倍回文的左半部分是个回文串,其中心一定位于\(i-\frac{pal[i]-1}2\)到\(i-1\)之间 ...
- BZOJ 2342: [Shoi2011]双倍回文 [Manacher + set]
题意: 求最长子串使得它有四个相同的回文串SSSS相连组成 枚举中间x 找右边的中间y满足 y-r[y]<=x y<=x+r[x]/2 用个set维护 注意中间只能是# #include ...
- [BZOJ2342]双倍回文
对每个大中心暴力找小中心即可. 代码: #include<iostream> #include<cstdio> #include<cstring> #define ...
- BZOJ 2342 [Shoi2011]双倍回文(manacher+并查集)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题目大意] 记Wr为W串的倒置,求最长的形如WWrWWr的串的长度. [题解] ...
- BZOJ 2342: [Shoi2011]双倍回文 马拉车算法/并查集
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1123 Solved: 408 题目连接 http://w ...
随机推荐
- [读书笔记2]《C语言嵌入式系统编程修炼》
第3章 屏幕操作 3.1 汉字处理 现在要解决的问题是,嵌入式系统中经常要使用的并非是完整的汉字库,往往只是需要提供数量有限的汉字供必要的显示功能.例如,一个微波炉的LCD上没有必要提供显示&qu ...
- 数据结构之单链表(C实现)
list.h #ifndef LIST_H #define LIST_H #include <iostream> #include <stdio.h> #include < ...
- 小白的python之路 序
计算机专科毕业,.net开发已有8年有余,中途断断续续,似懂非懂,积累了一些经验知识,但是不求甚解,属于那种一瓶不满半瓶子晃荡,这么一个状态. 主要从事web开发,涉及一些前端jq等,还有接口开发,搜 ...
- EasyUI系列学习(七)-Linkbutton(按钮)
一.加载组件 1.使用class加载 <a href="#" class="easyui-linkbutton">按钮</a> 2.使用 ...
- [ POI 2005 ] Bank Notes
\(\\\) Description 给出 \(N\) 种货币的面值 \(b_i\) 和个数 \(c_i\) ,求最少需要用多少个硬币凑出 \(Q\) 元钱,并输出任意一种方案. \(n\le 200 ...
- leetcode516 Longest Palindromic Subsequence
思路: 区间dp. 实现: class Solution { public: int longestPalindromeSubseq(string s) { int n = s.length(); ] ...
- github与git常用的一些基本配置与命令
首次Git设置:ssh-keygen -t ras -C "email@xxx" 生成SSH (共钥)将生成的SSH key复制到文本框中即可(title默认为邮箱名) 你的身份( ...
- Spartan6系列之GTP Transceiver的介绍与使用
1. 什么是GTP transceiver? GTP transceiver是FPGA里一种线速度达500Mb/sà6.6Gb/s的收发器,利用FPGA内部可编程资源可对其进行灵活地配置, ...
- 通过response对象的sendRedirect方法重定向网页
通过response对象的sendRedirect方法重定向网页 制作人:全心全意 使用response对象提供的sendRedirect()方法可以将网页重定向到另一个页面.重定向操作支持将地址重定 ...
- Network----轮询
轮询: 定时每隔多长时间刷新一次,但是,7X24的对服务器的压力会过大,因为在夜间或者是流量低峰期时,他还要持续工作. 客户端发一次请求,服务器就要相应一次. 长轮询: 和轮询的模式不同,长轮询是一次 ...