Palindrome poj3974
| Time Limit: 15000MS | Memory Limit: 65536K | |
| Total Submissions: 3280 | Accepted: 1188 |
Description
A string is said to be a palindrome if it reads the same both forwards and backwards, for example "madam" is a palindrome while "acm" is not.
The students recognized that this is a classical problem but couldn't come up with a solution better than iterating over all substrings and checking whether they are palindrome or not, obviously this algorithm is not efficient at all, after a while Andy raised his hand and said "Okay, I've a better algorithm" and before he starts to explain his idea he stopped for a moment and then said "Well, I've an even better algorithm!".
If you think you know Andy's final solution then prove it! Given a string of at most 1000000 characters find and print the length of the largest palindrome inside this string.
Input
Output
Sample Input
abcbabcbabcba
abacacbaaaab
END
Sample Output
Case 1: 13
Case 2: 6
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[];
int p[],t;
int fun()
{
int i,r=,c=,max=;
p[]=;
for(i=;i<t;i++)
{
p[i]=r>i?(r-i<p[(c<<)-i]?r-i:p[(c<<)-i]):;
while(a[i+p[i]+]==a[i-p[i]-])p[i]++;
max=max>p[i]?max:p[i];
if(p[i]+i>r)
{
r=p[i]+i;
c=i;
}
}
return max;
}
int main()
{
char x;
int tt=;
while()
{
t=;
a[t++]='#';
while(x=getchar())
{
if(x=='\n')break;
a[t++]='&';
a[t++]=x;
}
a[t++]='&';
if(a[]=='E')break;
printf("Case %d: %d\n",tt++,fun());
}
}
Palindrome poj3974的更多相关文章
- [poj3974]Palindrome_Manacher
Palindrome poj-3974 题目大意:求字符串的最长回文子串. 注释:$1\le strlen(s) \le 10^6$. 想法:介绍一种字符串算法——Manacher.求以每一个字符和字 ...
- 【学习笔记】字符串—马拉车(Manacher)
[学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...
- POJ----(3974 )Palindrome [最长回文串]
Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 5121 Accepted: 1834 Description Andy ...
- Palindrome(poj3974)(manacher算法)
http://poj.org/problem?id=3974 Palindrome Time Limit: 15000MSMemory Limit: 65536K Total Submissions: ...
- POJ3974 Palindrome
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- poj3974 Palindrome【回文】【Hash】【二分】
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 13157 Accepted: 5028 Desc ...
- POJ3974:Palindrome(Manacher模板)
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 14021 Accepted: 5374 题目链接 ...
- POJ3974 Palindrome (manacher算法)
题目大意就是说在给定的字符串里找出一个长度最大的回文子串. 才开始接触到manacher,不过这个算法的确很强大,这里转载了一篇有关manacher算法的讲解,可以去看看:地址 神器: #includ ...
- POJ--3974 Palindrome(回文串,hash)
链接:点击这里 #include<iostream> #include<algorithm> #include<stdio.h> #include<cstri ...
随机推荐
- 设置input框文字垂直居中和宽度
input { solid #999;height:22px; background:#ffffff; line-height:22px; margin:0px; padding:0px;/*表单输入 ...
- WPF DEV实现手风琴效果
说明 最近用WPF+DevExpress做项目时,需要做一个类似手风琴的效果,效果的界面如下.因为没有现成的控件,需要自定义模板,所以写了一个Demo和大家分享,项目中可以根据实际情况使用.如果你用不 ...
- LVS-DR实现web调度模式
author:JevonWei 版权声明:原创作品 实现LVS-DR调度web模式 拓扑环境 网络环境 RS1 RIP 192.168.198.138/24 VIP 192.168.198.100/3 ...
- Java double和 float丢失精度问题
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt357 由于对float或double 的使用不当,可能会出现精度丢失的问题. ...
- Intellij Idea 13 快捷键(与Eclipse比对)以及基本的设置
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt404 刚到新公司,用的台式机配置不给力,Eclipse很不给力,几个项目一起 ...
- [自制操作系统] 图形界面&VBE工具&MMIO显存&图形库/字库
本文记录了在JOS(或在任意OS)上实现图形界面的方法与一些图形库的实现. 本文中支持的新特性: 支持基本图形显示 支持中英文显示(中英文点阵字库) 相关:VBE VESA MMIO 点阵字库 Git ...
- 转: 【Java并发编程】之二十一:并发新特性—阻塞队列和阻塞栈(含代码)
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17511147 阻塞队列 阻塞队列是Java5并发新特性中的内容,阻塞队列的接口是Java. ...
- 集美大学网络1413第十二次作业成绩(个人作业3) -- Alpha阶段个人总结
题目 个人作业3--个人总结(Alpha阶段) 优秀作业链接:**068 未交:**087 个人作业3成绩 学号 姓名 总结(4) 5个问题(2.5) 自我评价(2.5) 博客互动 (1) 总分(10 ...
- Quartz入门指南
Quartz入门指南 看到官网的教程对于新手来说不够全面和连贯,因此结合自己的使用过程写下这个入门指南,用以解惑.本文基于Quartz2.2.2版本.请注意,本文为了易于上手,省略了许多重要的概念,建 ...
- 201521123037 《Java程序设计》第7周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 查看ArrayLi ...