poj3974 Palindrome 字符串
来源:互联网 发布:iphone同步软件 编辑:程序博客网 时间:2024/05/16 17:06
这个可以借鉴这篇博客http://blog.csdn.net/u013508213/article/details/29597201
#include <algorithm>#include <cstring>#include <cstdio>#include <iostream>#include <cmath>using namespace std;#define maxn 1100000char st[maxn],play[maxn<<1];int p[maxn<<1],len,cas;void solve(){ cas++; int len=strlen(st); memset(play,'#',sizeof(play)); for(int i=0;i<len;i++) { play[(i+1)<<1]=st[i]; } play[0]='?'; len=(len+1)<<1; play[len]='*'; int id=0,maxl=0,maxid=0; for(int i=0;i<len;i++) { if(i<maxid) { p[i]=min(p[2*id-i],maxid-i); } else { p[i]=1; } while(play[i-p[i]]==play[i+p[i]]) { p[i]++; } if(p[i]-1>maxl) { maxl=p[i]-1; } if(p[i]+i>maxid) { maxid=i+p[i]; id=i; } } printf("Case %d: %d\n",cas,maxl);}int main(){ while(1) { scanf("%s",st); if (strcmp(st,"END")==0) break; solve(); } return 0;}
0 0
- poj3974 Palindrome 字符串
- poj3974 Palindrome [字符串回文]
- 字符串-POJ3974-Palindrome
- POJ3974 Palindrome 解题报告【字符串】【Manacher】
- POJ3974 Palindrome
- poj3974 Palindrome
- poj3974 Palindrome
- POJ3974 Palindrome
- POJ3974 Palindrome (manacher算法)
- 【POJ3974】【Palindrome】【Manacher裸题】
- POJ3974 Palindrome(Manacher)
- poj3974 Palindrome(manacher)
- [学习][poj3974]manacher Palindrome
- poj3974 Palindrome(manacher)
- poj3974 Palindrome,回文串,Manacher
- POJ3974 Palindrome(Manacher算法)
- poj3974:Palindrome(manacher模板)
- poj3974 Palindrome (最长回文子串)
- IOS中数组的使用(NSArray, NSSet, NSDictionary)
- 学习210进度贴
- Openstack Juno on CentOS7
- 使用 HTML5 Boilerplate 开始 web 开发
- 【高清】全套arm 2440教学【视频教程】
- poj3974 Palindrome 字符串
- 笔试中常用的计算公式,排列与组合
- codeforces 之 C. String Manipulation 1.0
- ubuntu14.04 禁用unity
- windows xp 环境下安装theano
- TableTree4J的全结点展开, 显示居中以及Array.prototype
- 涉足计算机视觉领域要知道的~ (part2)
- Share folder or printer without password in Windows 7
- COM技术内幕 读书笔记——第一章 组件