博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3974 Palindrome
阅读量:7080 次
发布时间:2019-06-28

本文共 2207 字,大约阅读时间需要 7 分钟。

PalindromeTime Limit: 15000MS Memory Limit: 65536K

Total Submissions: 2939 Accepted: 1081
Description
Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the largest palindrome in a string?"
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
Your program will be tested on at most 30 test cases, each test case is given as a string of at most 1000000 lowercase characters on a line by itself. The input is terminated by a line that starts with the string "END" (quotes for clarity).
Output
For each test case in the input print the test case number and the length of the largest palindrome.
Sample Input
abcbabcbabcba
abacacbaaaab
END
Sample Output
Case 1: 13
Case 2: 6
Source
Seventh ACM Egyptian National Programming Contest

 

//10944K    204MS    C++    840B//和hdu 3068 一样,求最长回文串,有模板 //不懂可以看看 算法学习里的有关介绍 #include
#include
#define N 1000005char c[2*N],c0[N];int p[2*N];int k,n;int Min(int a,int b){ return a
i) p[i]=Min(p[2*id-i],mx-i); else p[i]=1; for(;c[i-p[i]]==c[i+p[i]];p[i]++); if(mx
maxn) maxn=p[i]; } printf("Case %d: %d\n",k++,maxn-1);}int main(void){ k=1; while(scanf("%s",c0)!=EOF) { if(strcmp(c0,"END")==0) break; rebuild(); pk(); } return 0;}

 

转载于:https://www.cnblogs.com/GO-NO-1/articles/3348572.html

你可能感兴趣的文章
面向对象二次整理(基础,属性引用,方法引用.绑定方法)
查看>>
[C++参考]私有成员变量的理解
查看>>
学习该有的思维方式
查看>>
Linux:查看磁盘空间占用情况
查看>>
redis发布订阅
查看>>
dubbo+zookeeper
查看>>
3D打印材料的发展现状(1)
查看>>
GPGPU之应用于Mapped Reduced
查看>>
html dom的nodetype值介绍,HTML DOM nodeType用法及代码示例
查看>>
html怎么对多个td应用样式,html – 如何将样式类应用于td类?
查看>>
Proxmox集群ceph报“ceph 1pg inconsistent”错误解决备忘
查看>>
多级菜单系统安装维护shell脚本实现企业级案例
查看>>
那些年,我玩过的操作系统
查看>>
Lync Server 2013标准版升级Skype for Business Server 2015实战(上)
查看>>
新浪、万网前系统架构师高俊峰:统一监控报警平台架构设计思路
查看>>
2011-9-25俱乐部活动
查看>>
JMeter正则表达式提取器
查看>>
Nginx
查看>>
How To Enable‘root’Account Login Solaris 11 Directly
查看>>
MongoDB学习初步
查看>>