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的更多相关文章

  1. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  2. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  3. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

  4. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  5. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  6. [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 ...

  7. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  8. [LeetCode] Palindrome Partitioning II 拆分回文串之二

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  9. [LeetCode] Palindrome Partitioning 拆分回文串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  10. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

随机推荐

  1. iOS CoreData (1)

    下面开始学习一下CoreData. Core Data不是一个关系型数据库,也不是关系型数据库管理系统(RDBMS). Core Data 为数据变更管理.对象存储.对象读取恢复的功能提供了支持. 它 ...

  2. mysql 插入语句

    mysql 插入语句 什么时候用单引号,什么时候不用? 1.先创建一个表 create table user(username varchar(255),age int,marry boolean,b ...

  3. Android开发之适配器-ListView适配器的重复数据

    适配器是Android中的数据与View视图的桥梁,作用就是将数据通过适配器显示到对应的View视图上. 工作中,在用ListView做适配器数据时候,有些人肯定碰见过,如何优化效率,但是又出现重复数 ...

  4. SQL Server 2005恢复数据库详细图文教程

    不少需要用到sql2005的程序,有很多新手还是会操作,这里写个详细的图文教程送个菜鸟们,高手请飘过.适用于独立主机的朋友使用,如果你还没安装,请按照这个教程来安装 SQL Server 2005图文 ...

  5. IntelliJ插件安装

    1. 插件管理器在线安装 在IntelliJ插件管理页面([FileàSettingsàIDE SettingsàPlugins]),点击[Browse repositories-]按钮,在搜索框内输 ...

  6. angularjs 更新局部作用域

    前几天项目需要,做了一个背景遮罩的弹出框,html采用js动态添加进去的,结果发现angularjs绑定在这里面不起作用,搜索下解决了,记录下: var smallApplyParent = docu ...

  7. mysql select 语法

    格式:select [选项子句] 字段表达式子句 [from子句] [where子句] [group by子句] [having子句] [order by子句] [limit子句]; 提示:子句的顺序 ...

  8. iis7.5 应用程序池 经典模式和集成模式的区别

    在 IIS 7.5 中,应用程序池有两种运行模式:集成模式和经典模式. 应用程序池模式会影响服务器处理托管代码请求的方式. 如果托管应用程序在采用集成模式的应用程序池中运行,服务器将使用 IIS 和 ...

  9. .NET下的加密解密大全(2):对称加密

    本博文列出了.NET下常用的对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. 公共代码[csharp]static byte[] CreateKey(int num) {     byt ...

  10. OC - 13.数据解析(JSON与XML)

    ##数据交互格式 服务器返回给用户的数据,通常是以下两种方式: JSON XML JSON 一种轻量级的数据数据格式,体积比XML小,是服务器返回给移动端通常采用的格式 用使用JSON文件中的数据,需 ...