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 ... 
随机推荐
- 网络唤醒原理浅析(Wake On LAN)
			之前我的一篇文章<网络唤醒全攻略(Wake On Lan)>介绍过如何设置远程唤醒电脑,着重于使用,这篇主要从原理方面解析一下当中的奥妙: 原理 将唤醒魔术包发送的被唤醒机器的网卡上,魔术 ... 
- css关键字unset
			今天遇到了一个css属性 display:unset 以为是新增的display的属性值,查了好久,发现并没有这个属性值, 后来发现了unset是css的关键字,将一个属性的属性值设置为unset,目 ... 
- el-input监听不了回车事件
			vue使用element-ui的el-input监听不了回车事件,原因应该是element-ui自身封装了一层input标签之后,把原来的事件隐藏了,所以如下代码运行是无响应的: <el-inp ... 
- Linq 实现sql中的not in和in条件查询
			T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products Where CategoryID in (1, 2) T-S ... 
- 第4阶段——制作根文件系统之分析init进程(2)
			本节目标: (1) 了解busybox(init进程和命令都放在busybox中) (2) 创建SI工程,分析busybox源码来知道init进程做了哪些事情 (3) 分析busybox中init进 ... 
- Project 10:简单图像的绘制
			目标:绘制如图图像 #include <stdio.h> int main() { int n,i,j,o,k=0; printf("请输入一个数:"); scanf( ... 
- cocos2dx lua中异步加载网络图片,可用于显示微信头像
			最近在做一个棋牌项目,脚本语言用的lua,登录需要使用微信登录,用户头像用微信账户的头像,微信接口返回的头像是一个url,那么遇到的一个问题就是如何在lua中异步加载这个头像,先在引擎源码里找了下可能 ... 
- 转:【Java集合源码剖析】Hashtable源码剖析
			转载请注明出处:http://blog.csdn.net/ns_code/article/details/36191279 Hashtable简介 Hashtable同样是基于哈希表实现的,同样每个元 ... 
- HTML canvas  笑脸
			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ... 
- Beta阶段项目复审
			复审人:王李焕 六指神功:http://www.cnblogs.com/teamworkers/ wt.dll:http://www.cnblogs.com/TeamOf/ 六个核桃:http://w ... 
