poj 3974 Palindrome 最长回文
来源:互联网 发布:java装饰模式好处 编辑:程序博客网 时间:2024/06/05 00:17
Manacher算法。
不过不知道为什么我写的比比人慢这么多。。。。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=2e6+9;char a[maxn];int dp[maxn];inline int max(int &a,int &b){ if(a>b) return a; return b;}int main(){ int tt=0; while(1) { char tmp; for(int i=0;;) { scanf("%c",&tmp); if(tmp=='\n') {a[++i]=0;break;} else if(tmp!=' ') { a[++i]=tmp; a[++i]='#'; } } if(a[1]=='E') break; int top=0,n=strlen(a+1); dp[0]=0,a[0]=-1; for(int i=1,t,s;i<=n;i++) { if(top+dp[top]<i) { top=i; t=i-1,s=i+1; while(a[t]==a[s]) t--,s++; dp[i]=s-i-1; } else { if(dp[top-(i-top)]+i<top+dp[top]) dp[i]=dp[top-(i-top)]; else { s=top+dp[top]+1; t=i-(s-i); while(a[t]==a[s]) t--,s++; dp[i]=s-i-1; top=i; } } } int ans=0; for(int i=1;i<=n;i++) if(a[i]=='#') ans=max(ans,dp[i]+1>>1<<1); else ans=max(ans,(dp[i]>>1<<1)+1); printf("Case %d: %d\n",++tt,ans); } return 0;}
- poj 3974 Palindrome 最长回文
- HDU 3068 最长回文 / POJ 3974 Palindrome
- POJ 3974 Palindrome 最长回文子串
- poj 3974 Palindrome 【最长连续回文子串,Manacher算法】
- POJ 3974 Palindrome 最长回文子串(manacher算法)
- POJ 3974 Palindrome 求最长回文子串 Manacher
- POJ 3974 Palindrome【最长回文串(Manacher模板)】
- poj 1159 Palindrome(最长回文子串)
- POJ 4617 Palindrome(最长回文子串)
- POJ 3974 Palindrome 回文串
- poj 3974 Palindrome(最长回文子串,处理大数,Manacher算法)
- poj 3974 Palindrome 裸的最长回文子串Mancher算法O(n)
- POJ-3974-Palindrome- Manacher 马拉车算法(On寻找最长回文串)
- poj 3280 Cheapest Palindrome(最长回文串变形)
- POJ 1159 Palindrome(动态规划:最长回文子序列)
- POJ 1159 Palindrome(最长回文子序列+滚动数组)
- POJ 1159 Palindrome(回文串,最长公共子序列)
- [Leetcode] Longest Palindrome 最长回文
- 快速检测空间三角形相交算法的代码实现(Devillers & Guigue算法)
- 利用python实现hadoop stream操作遇到的Broken pipe错误
- COT (spoj)
- codeforces 263C. Circle of Numbers
- iOS7: 如何获取不变的UDID
- poj 3974 Palindrome 最长回文
- win7 64下暗黑世界V1.1 服务器端及客户端的安装及运行 成功
- matlab中EYEDIAGRAM(X, N)简介
- Windows平台下NDK环境搭建
- 单链的remove
- DOS命令大全(经典收藏)
- Selenium 2 跑safari浏览器 (在windows XP系统上)
- 《暗黑世界》win下详细编译步骤,亲测通过
- ACE数据接收中粘包及半包的处理