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 ...
随机推荐
- Servlet中文乱码解决方法
程序中的输入输出都是以流的形式保存的,流中保存的实际上全都是字节文件. 字节流和字符流的区别: 在Java.io包中操作文件内容的主要有两大类:字节流.字符流,两类都分为输入和输出操作. 在字节流中输 ...
- HDU2088JAVA
Hot~~招聘——巴卡斯(杭州),亚信科技,壹晨仟阳(杭州) Box of Bricks Time Limit: 1000/1000 MS (Java/Others) Memory Limit: ...
- 在KALI LINUX中安装JAVA JDK
1. 下载最新的JAVA JDK jdk-8u91-linux-x64 2. 解压缩文件并移动至/opt tar -xzvf jdk-8u91-linux-x64.tar.gz mv jdk1.8.0 ...
- RedHat7搭建Nginx+Apache+PHP
Nginx做为前端服务器(本机IP:192.168.136.104),将访问PHP页面的动态请求转发给Apache服务器(只监听本地回环地址172.0.0.1:80) 安装Apache# yum -y ...
- sql 删除表数据truncate delete drop的区别
已下内容为转载内容:学习之用 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句(数据定义语言),执行后会自动提交. ...
- linux常用命令(自我积累)
创建目录:mkdir + 目录名 使文件可执行:chmod +x filename 执行文件:./filename 来执行您的脚本 {程序必须以下面的行开始(必须方在文件的第一行): #!/bin/s ...
- java中事件处理探究
事件的触发可以源于用户,也可以用代码来主动设置事件的发生.如setSelected()java.awt.event中 听众接口 事件类 适配器类 ComponentListener Conta ...
- 类库探源——System.Exception
一.MSDN描述 Exception 类: 表示在应用程序执行期间发生的错误 命名空间 : System 程序集: mscorlib.dll 继承关系: 常用属性(含字段)和方法: 1. 属性Me ...
- [Introduction to programming in Java 笔记] 1.3.8 Gambler's ruin simulation 赌徒破产模拟
赌徒赢得机会有多大? public class Gambler { public static void main(String[] args) { // Run T experiments that ...
- php的各种配置
问题:1.如果去掉URL_MODEL=1时的index.php第一步:把Apache配置文件中的LoadModule rewrite_module modules/mod_rewrite.so 取消注 ...