Girls' research - HDU 3294 (Manacher处理回文串)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = 1e6+;
const int oo = 1e9+; char s[MAXN];
int p[MAXN]; int Manacher(int len)
{
int id=, Max=; for(int i=; i<len; i++)
{
p[i] = ; if(p[id]+id > i)
p[i] = min(p[id*-i], p[id]+id-i); while( s[ i+p[i] ] == s[ i-p[i] ] )
p[i]++; if(p[id]+id < p[i]+i)
id = i; if(p[Max] < p[i])
Max = i;
} return Max;
} int main()
{
char ch[]={}; while(scanf("%s%s", ch, s) != EOF)
{
int i, k=ch[]-'a';
int N = strlen(s); for(i=N; i>=; i--)
{
if(i != N)
{
s[i] -= k;
if(s[i] < 'a')
s[i] += ;
}
s[i+i+] = s[i];
s[i+i+] = '#';
}
s[] = '$'; k = Manacher(N+N+); if(p[k] <= )
printf("No solution!\n");
else
{ int L = (k-p[k])/, R = k+p[k]; printf("%d %d\n", L, L+p[k]-); for(i=k-p[k]+; i<R; i++)
{
if(s[i] != '#')
printf("%c", s[i]);
}
printf("\n");
}
} return ;
}
Girls' research - HDU 3294 (Manacher处理回文串)的更多相关文章
- hdu 3294 manacher 求回文串
感谢: http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/ O(n)求给定字符串的以每个位置为中心的回文串长度. 中心思想:每次计算位 ...
- Girls' research HDU - 3294(马拉车水题)
题意: 求最长回文串 长度要大于等于2 且输出起点和终点 输出回文串字符 这个字符还是要以给出的字符为起点a 输出 解析: 分析一下s_new串就好了 #include <iostream& ...
- HDU 5340——Three Palindromes——————【manacher处理回文串】
Three Palindromes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- manacher算法——回文串计算的高效算法
manacher算法的由来不再赘述,自行百度QWQ... 进入正题,manacher算法是一个高效的计算回文串的算法,回文串如果不知道可以给出一个例子:" noon ",这样应该就 ...
- HDOJ/HDU 2163 Palindromes(判断回文串~)
Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...
- hdu 3613 扩展kmp+回文串
题目大意:给个字符串S,要把S分成两段T1,T2,每个字母都有一个对应的价值,如果T1,T2是回文串(从左往右或者从右往左读,都一样),那么他们就会有一个价值,这个价值是这个串的所有字母价值之和,如果 ...
- (回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit:1000MS Memory Limit:32 ...
- HDU 5371 Hotaru's problem (Manacher,回文串)
题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...
- Hdu 3294 Girls' research (manacher 最长回文串)
题目链接: Hdu 3294 Girls' research 题目描述: 给出一串字符串代表暗码,暗码字符是通过明码循环移位得到的,比如给定b,就有b == a,c == b,d == c,.... ...
随机推荐
- Oracle dblink的创建及使用
在工作中遇到的情况简单说下: --首先要赋予用户创建dblink的权限.grant resource to ods_nwsc;grant create database link to ods_nws ...
- Scrum教练不应兼任product owner
ScrumMasters Should Not Also Be Product Owners(中文翻译) December 2, 2014 by Mike Cohn 翻译:2015.2.18 by o ...
- 关于@property()的那些属性及ARC简介【nonatomic,atomic,assign,retain,strong,weak,copy。】
@property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的gette ...
- jstl--c:choose标签
今天使用c:choose标签,一直报错: 严重: Servlet.service() for servlet CheckIncome threw exceptionorg.apache.jasper. ...
- this point
// this.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> using namespa ...
- asp.net Handler中的IsReusable属性及在Handler中使用Session
大家在用HttpHandler的时候,一般都会有两个大的疑问(当然,前提是你有钻研精神的话,呵呵) 1. IsReusable到底什么意思? 老实说,这个属性很多人都感兴趣,但搞懂的人确实不多.MSD ...
- windows core audio apis
这个播放流程有一次当初不是很理解,做个记录,代码中的中文部分,原文档是有解释的:To move a stream of rendering data through the endpoint buff ...
- 递归 与 js 对象的引用
<script> //递归 function test(n) { if (n == 1) { return 1 } console.log(n) return n * test(n - 1 ...
- C#遍历所有的Textbox控件并赋值为String.Empty
foreach (Control control in this.Controls) { if (control.GetType().Name.Equals("TextBox")) ...
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; us ...