manecher
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[],s[];
int n,l,p[],ans,k=-,m=;
void manacher()
{
int pos=,id=,x=;
for(int i=;i<=n-;i++)
{
if(pos<=i) x=;
else x=min(p[*id-i],pos-i);
while(s[i+x]==s[i-x]) x++;
p[i]=x;
if(i+x>pos)
{
pos=i+x;
id=i;
}
}
}
int main()
{
while(cin>>a)
{
if(a[]=='E') return ;
ans=,n=;
l=strlen(a);
s[n++]='%';
for(int i=;i<l;i++)
{
s[n++]='#';
s[n++]=a[i];
}
s[n++]='#';
s[n]='@';
manacher();
for(int i=;i<=n;i++)
if(ans<p[i])
{
ans=p[i];
k=i;
}
if(s[k]=='#') printf("Case %d: %d\n",m++,ans/*);
else printf("Case %d: %d\n",m++,ans/*-);
} }
manecher的更多相关文章
- Palindrome [Manecher]
Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 12214 Accepted: 4583 Descript ...
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...
- wannafly 挑战赛8 E 小G的项链(manecher)
链接:https://www.nowcoder.com/acm/contest/57/E 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit ...
- 【字符串】manacher算法
Definition 定义一个回文串为从字符串两侧向中心扫描时,左右指针指向得字符始终相同的字符串. 使用manacher算法可以在线性时间内求解出一个字符串的最长回文子串. Solution 考虑回 ...
- NOIP2017赛前考试注意事项总结
考前: 考试前把读入优化和库以及对拍文件打好做好准备工作,另外注意放松心态,太紧张了肯定考不好··将自己的注意力集中起来 考场策略: 考试的基本策略是对每于道题先想个20分钟,如果想不出个靠谱的方 ...
- 【CQ18高一暑假前挑战赛2】标程
[昨晚打校赛,5个小时打完很累了,所以搞忘出题了...对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大] [A:bush博弈] #include<bits/st ...
随机推荐
- git搜索--grep
1. 查找某个关键字(比如函数名): $ git grep xmmap config.c: contents = xmmap(NULL, contents_sz, PROT_READ, ); git- ...
- httpclient调用方法
/** * GET请求 * * @param url * 请求url,参数拼在请求串中 */ public static String get(String url) ...
- jquery datatable 参数api
jQuery 的插件 dataTables 是一个优秀的表格插件,提供了针对表格的排序.浏览器分页.服务器分页.筛选.格式化等功能.dataTables 的网站上也提供了大量的演示和详细的文档进行说明 ...
- php 特定类型测试函数
is_array() 检查变量是否是数组 is_double().is_float().is_real() 检查变量是否是浮点数 is_long().is_int().is_integer()检查变量 ...
- error while loading shared libraries: libmcrypt.so.4
/usr/local/php/sbin/php-fpm: error while loading shared libraries: libmcrypt.so.4: cannot open share ...
- code.google.com
https://github.com/couchbase/sync_gateway/issues/492 This list shows the current base import paths, ...
- Sockets
Sockets time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- java synchronized 线程同步机制详解
Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchronized(this ...
- 10款超酷实用的jQuery焦点图赏析及源码
1.jquery整屏滚动插件Scrollify Scrollify是一个jQuery插件协助整屏滚动和顺利拍摄部分.完全可配置和优化. 在线演示 源码下载 2.jquery实现网易邮箱页面插件full ...
- c++内存流
1.MemoryStream.h文件内容 ifndef _MEM_STREAM_H_ #define _MEM_STREAM_H_ #include <string> class CMem ...