Palindrome
poj3974:http://poj.org/problem?id=3974
题意:求给定长度最长回文串的长度。
题解:直接套manacher,搞定。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e6+;
char str1[N],str[N<<];
int rad[N];
char temp;
void Manacher(int *rad,char *str,int n){
int i,mx=,id;
for(int i=;i<n;i++){
if(mx>i){
rad[i]=min(rad[*id-i],mx-i);
}
else
rad[i]=;
for(;str[i-rad[i]]==str[i+rad[i]];rad[i]++){
if(rad[i]+i>mx){
mx=rad[i]+i;
id=i;
}
}
}
} int main(){
int cas=;
while(~scanf("%s",str1)){
if(str1[]=='E')break;
int nn=strlen(str1);
int n=*nn+;
str[]='$';
for(int i=;i<=nn;i++){
str[*i+]='#';
str[*i+]=str1[i];
}
memset(rad,,sizeof(rad));
Manacher(rad,str,n);
int ans=;
for(int i=;i<=n;i++){
if(rad[i]>=&&rad[i]>ans){
ans=rad[i];
}
}
printf("Case %d: %d\n",cas++,ans-);
}
}
Palindrome的更多相关文章
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Palindrome Linked List 回文链表
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- [LeetCode] Valid Palindrome 验证回文字符串
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
随机推荐
- linux 启动流程图
http://blog.163.com/x_ares/blog/static/101548562011710112613165/ http://baogf92.blog.51cto.com/10869 ...
- (转载)github简单使用教程
github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开.对于一般人来说公共仓库就已经足够了,而且我们也没多少代码来管理,O(∩_∩)O ...
- java web 前端页面的分页逻辑
<div class="divBody"> <div class="divContent"> <!--上一页 --> < ...
- mysql锁表和解锁语句分享
对于MySQL来说,有三种锁的级别:页级.表级.行级 页级的典型代表引擎为BDB. 表级的典型代表引擎为MyISAM,MEMORY以及很久以前的ISAM. 行级的典型代表引擎为INNODB. ...
- JS 判断 Radio 单选按钮是否为选中状态 并弹出 值信息
今天项目中所解决的问题:JS 判断 Radio 单选按钮是否为选中状态 并弹出 值信息,一开始总是获取不到 radio 的值,后来发现逻辑存在些问题,特此共享该代码留笔记 和 分享给遇到 这类问题的 ...
- Android 网络视频播放器
项目概要: 1.登录界面 2.播放列表 3.播放界面
- LINQ数据库连接对象制造工厂
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- javascript类继承系列一
js中没有提供类(class,抽象类,接口等高级的抽象),可以用new,但new的function的对象,构造器 但在js中可以通过function来模拟类的一些特性function fun_name ...
- C# Ref 与out 的区别
在C#中,有四种传递参数方式: 1. 传值 (value) : 无额外修饰符 2. 传址(reference) : 需修饰符Ref,传入函数的参数必须先赋值 3. 输出参数(output): 需修饰符 ...
- .NET(C#):获取进程的内存私有工作集
当前.NET Framework(.NET 4.0)的Process仅提供进程的内存工作集的获取(通过WorkingSet64属性),而没有提供对私有工作集的获取.注意在Windows Vista之后 ...