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 ...
随机推荐
- Optimizing Linux network TCP/IP kernel parameters
You can verify the Linux networking kernel parms from the root user with these commands::Many Oracle ...
- ServletContext对象--三大域对象
Servlet三大域对象的应用 request.session.application(ServletContext) ServletContext是一个全局的储存信息的空间,服务器开始就存在,服务器 ...
- Java Post 数据请求和接收
这两天在做http服务端请求操作,客户端post数据到服务端后,服务端通过request.getParameter()进行请求,无法读取到数据,搜索了一下发现是因为设置为text/plain模式才导致 ...
- c#获取远程图片的方法
public static int SaveImageFromWeb(string imgUrl, string path) { var aaa = Environment.CurrentDirect ...
- 浅谈Mamcached集成web项目
1.资源文件配置 config.properties 添加 #memcached服务器地址 memchchedIP=192.168.1.8 2.编写工具类 MemUtils package cn.co ...
- 类似与三元表达式的 json 读取值
需要先在项目中添加 json的dll json 序列里面的key在item.feeType里面必须存在 否则会报 未将对象引用到实例 myDr["feeType"] = Newto ...
- 模版引擎(NVelocity)开发
在net中用模版开发,在handler中用到了大量的html代码.为解决这个问题,我可以采用模版引擎(NVelocity)进行开发.1.首先需要将NVelocity.dll文件放入项目,其次引用.2. ...
- document library\ picture library\Asset Library的默认文件夹
document library\ picture library\Asset Library的默认文件夹? document library 默认文件夹:Forms picture library默 ...
- orainstRoot.sh到底执行了哪些操作
1 #!/bin/sh 1 #!/bin/sh 2 AWK=/bin/awk 3 CHMOD=/bin/chmod 4 CHGRP=/bin/chgrp ...
- O-C相关-03:面向对象概念的具体介绍
1.面向对象的概念 面向对象(object-oriented ;简称: OO) 至今还没有统一的概念,我这里把它定义为:按人们认识客观世界的系统思维方式,采用基于对象(实体)的概念建立模型,模拟客观世 ...