(回文串 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\)开头的最长回文串长 ...
 
随机推荐
- neo4j 常用命令查询,以及更新 节点 的 label 名 和  property  名
			
常用命令查询 https://neo4j.com/docs/cypher-refcard/current/ 更新节点的 labels 有时候 发现节点的 label 名字起错了怎么修改呢?!一个节点是 ...
 - MySQL中实现Oracle里面 rank()over ( PARTITION BY ORDER BY) 分类分组功能
			
各班级学生成绩测试表 select * from TMP_A; 实现目的: 按照班级分类后按照分数倒序排序 采用MySQL变量简单实现,SQL如下: SELECT a.stu_id,a.point, ...
 - tensor flow 安装
			
http://blog.csdn.net/nxcxl88/article/details/52704877?locationNum=13 安装后,一定要运行这句话后 $ source activa ...
 - js 获取input选择的图片的信息
			
1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...
 - php页面的基本语法
			
概述: 1. PHP 脚本在服务器上执行,然后将纯 HTML 结果发送回浏览器. 2. PHP 脚本以 <?php 开始,以 ?> 结束,可以放到文档中的任何位置. 3. 当 PHP 解析 ...
 - day7:vcp考试
			
Q121. An ESXi 6.x host in the vCenter Server inventory has disconnected due to an All Paths Down (AP ...
 - [leetcode]438. Find All Anagrams in a String找出所有变位词
			
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
 - php 账号不能同时登陆,当其它地方登陆时,当前账号失效
			
解决的思路是每当用户登陆时我们必需记录当前的用户id和session_id,如果有人在其它地方用此账号登陆时,我们把此用户id对应的session_id的session文件删除,并重新记录当前的ses ...
 - 【SQL模板】四.插入/更新 列模板TSQL
			
---Name: 插入/更新 列模板.sql ---Purpose: 用于更新 数据库中 列 的脚本模板 ---Author: xx ---Time: 2015-12-18 10:26:06 ---R ...
 - ServiceStack支持跨域提交
			
//ServiceStack对浏览器有一定的限制 //修改AppHost.cs文件 using Funq;using ServiceStack;using ServiceStackTest.Servi ...