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 ...
随机推荐
- C# - 类型
C#是一门使用OOP技术的编程语言(Object Oriented Programming 面向对象编程)面向对象最重要的特性就是接口.继承.多态 C#中所有的事物都可以看做是一个对象 对象由类型来创 ...
- Apache CXF 3.0: CDI 1.1 Support as Alternative to Spring--reference
With Apache CXF 3.0 just being released a couple of weeks ago, the project makes yet another importa ...
- android注解使用详解(图文)
在使用Java的SSH框架的时候,一直在感叹注解真是方便啊,关于注解的原理,大家可以参考我的另一片文章Java注解详解.最近有时间研究了android注解的使用,今天与大家分享一下. android中 ...
- 【Android】数据存储-SharedPreferences存储
简单介绍:SharedPreferences是使用键值对的方式来存储数据的,也就是说,当保存一条数据的时候,给这条数据提供一个键,如果需要读取数据,只需要通过这个键就可以提取到对应的数据. 一:存储数 ...
- Linux平台的boost安装全解
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- ECshop--搜索模块细究
ecshop细究 今天看了下ecshop搜索这块,前台数据一直到后台查询再返回前台.大致是这么个过程,首先,在index.dwt文件内,body下面引入了 <!-- #BeginLibraryI ...
- 版本控制SVN与Eclipse4.4.1集成 ( eclipse svn:E175002错误解决 )
Eclipse版本--Luna Service Release 1(4.4.1) SVN版本-----1.8.X 系统OS-------ubuntu 14.04 LTS 1.通过地址安装 Help-& ...
- .NET设计模式(7):创建型模式专题总结(Creational Pattern)
):创建型模式专题总结(Creational Pattern) 创建型模式专题总结(Creational Pattern) --.NET设计模式系列之七 Terrylee,2006年1月 转载: ...
- sql 嵌套事务学习笔记
以下内容根据此官方文档修改:http://technet.microsoft.com/zh-cn/library/ms189336(v=sql.105).aspx 嵌套事务的使用场景或者说目的主要是为 ...
- A题笔记(2)
No. 1505 文件读相关 #include <fstream> #include <sstream> <fstream>支持文件的IO <sstream& ...