(回文串 Manacher )Girls' research -- hdu -- 3294
http://acm.hdu.edu.cn/showproblem.php?pid=3294
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
First step: girls will write a long string (only contains lower case) on the paper. For example, "abcde", but 'a' inside is not the real 'a', that means if we define the 'b' is the real 'a', then we can infer that 'c' is the real 'b', 'd' is the real 'c' ……, 'a' is the real 'z'. According to this, string "abcde" changes to "bcdef".
Second step: girls will find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.
Input
Each case contains two parts, a character and a string, they are separated by one space, the character representing the real 'a' is and the length of the string will not exceed 200000.All input must be lowercase.
If the length of string is len, it is marked from 0 to len-1.
Output
If you find one, output the start position and end position of palindromic string in a line, next line output the real palindromic string, or output "No solution!".
If there are several answers available, please choose the string which first appears.
Sample Input
Sample Output
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm> using namespace std;
#define INF 0x3f3f3f3f
#define N 1000007 char s[N], S[N], str[N];
int p[N], Mid; int Manacher()
{
int MaxLen = , index = , ans = ;
int len = strlen(s);
Mid = ; for(int i=; i<len; i++)
{
if(MaxLen>i) p[i] = min(p[index*-i], MaxLen-i);
else p[i] = ; while(s[i-p[i]]==s[i+p[i]] )
p[i]++; if(p[i]+i>MaxLen)
{
MaxLen = p[i] + i;
index = i;
} if(p[i]>ans)
{
ans = p[i];
Mid = i;
}
}
return ans-;
} int main()
{
char ch[]; while(scanf("%s%s", ch, S)!=EOF)
{
int i, len = strlen(S), number;
char c; number = ch[]-'a'; s[] = '$';
for(i=; i<len; i++)
{
c = S[i] - number;
if(c<'a')
c += ;
S[i] = c; s[i*+] = '#';
s[i*+] = S[i];
}
s[i*+] = '#';
s[i*+] = ; int ans = Manacher(); if(ans<)
printf("No solution!\n");
else
{
int L = Mid/-(ans+)/;
printf("%d %d\n", L, L+ans-);
memset(str, , sizeof(str));
strncpy(str, S+L, ans);
printf("%s\n", str);
}
}
return ;
}
(回文串 Manacher )Girls' research -- hdu -- 3294的更多相关文章
- Girls' research - HDU 3294 (Manacher处理回文串)
题目大意:给以一个字符串,求出来这个字符串的最长回文串,不过这个字符串不是原串,而是转换过的,转换的原则就是先给一个字符 例如 'b' 意思就是字符把字符b转换成字符 a,那么c->b, d-& ...
- HDU 3613 Best Reward ( 拓展KMP求回文串 || Manacher )
题意 : 给个字符串S,要把S分成两段T1,T2,每个字母都有一个对应的价值,如果T1,T2是回文串,那么他们就会有一个价值,这个价值是这个串的所有字母价值之和,如果不是回文串,那么这串价值就为0.问 ...
- (回文串 )Best Reward -- hdu -- 3613
http://acm.hdu.edu.cn/showproblem.php?pid=3613 Best Reward Time Limit: 2000/1000 MS (Java/Others) ...
- 最长回文---hdu3068 (回文串 manacher 算法模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题意很清楚:就是求一个串s的子串中最长回文串的长度:这类题用到了manacher算法 #incl ...
- BZOJ 2342 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2342 思路:先跑一遍Manacher求出p[i]为每个位置为中心的回文半径,因为双倍回文串 ...
- BZOJ 2565 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2565 题意:中文题 思路:定义L[i],R[i].表示以i为左端点/右端点时,最长回文串长 ...
- POJ 3974 回文串-Manacher
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...
- 【回文串-Manacher】
Manacher算法能够在O(N)的时间复杂度内得到一个字符串以任意位置为中心的回文子串.其算法的基本原理就是利用已知回文串的左半部分来推导右半部分. 转:http://blog.sina.com.c ...
- BZOJ 2565: 最长双回文串 [Manacher]
2565: 最长双回文串 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1842 Solved: 935[Submit][Status][Discu ...
- BZOJ.2565.[国家集训队]最长双回文串(Manacher/回文树)
BZOJ 洛谷 求给定串的最长双回文串. \(n\leq10^5\). Manacher: 记\(R_i\)表示以\(i\)位置为结尾的最长回文串长度,\(L_i\)表示以\(i\)开头的最长回文串长 ...
随机推荐
- js原生实现 无缝滚动图片
<!-- 无缝滚动图片开始 --> <div id=demopic style="OVERFLOW: hidden; WIDTH: 100%; COLOR: #fff; H ...
- Access denied for user 'root'@'localhost' (using password:YES)解决方法
Access denied for user 'root'@'localhost' (using password:YES)解决方法 在MySQL的使用过程中,我们可能会碰到“Access denie ...
- Pandas数据规整
Pandas数据规整 数据分析和建模方面的大量编程工作都是用在数据准备上的,有时候存放在文件或数据库中的数据并不能满足数据处理应用的要求 Pandas提供了一组高级的.灵活的.高效的核心函数和算法,它 ...
- Android使用HTTPS进行IP直连握手失败问题(okHttp)
为什么要使用ip直连这种方式去请求我们的服务器呢?这其实和国内运营伤有关,运营商有时为了利益会将你的域名劫持换成他人的域名,为了防止这种情况的发生通用的解决办法要么联系运营商要么就只能使用ip直连了. ...
- poj3278-Catch That Cow 【bfs】
http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- Winsock版本的“hello world!”
1.基于TCP协议的“hello world!” 1)服务器端:WSAStartup()->socket()->bind()->listen()->accept()->s ...
- Only POT texture can be compressed to PVRTC format
在图片压缩格式 报这个Warning的时候,意思是该图片必须要采用2的幂次方大小才能使用该格式. POT: Power of Two. 采取方式是在advanced里边,把Non Power of 2 ...
- swift - 画图 - 画矩形,虚线,圆和半圆
import UIKit class JYJYBouncedCouponsViewCellBgView: UIView { //一定要在这里设置 背景色, 不要再draw里面设置, override ...
- linux引导系统
一.linux引导系统 1.选择操作系统 /etc/grub.conf 设置grub引导装载程序口令,使用单用户模式时必须输入此密码 password --md5 md5后的密码字符串(可以通过gru ...
- PL/Sql快速执行 insert语句的.sql文件
当全是 insert语句的.sql文件太大时(insert 语句条数太大),直接打开执行sql文件,pl/sql会卡死. 这是可以用pl/sql的命令窗口来执行.sql文件,操作步骤如下: 1.新建命 ...