HDU3068 最长回文(manacher)
来源:互联网 发布:mac wi fi 未安装硬件 编辑:程序博客网 时间:2024/05/12 01:43
题意:最长回文。
思路:manacher算法。可以作模板了。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<vector>#include<map>#include<algorithm>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const int mod = 1000000007;const int maxn = 110005;int manacher(char s[], char str[], int p[]){ int len = strlen(s); str[0] = '*';//第一位是*,最后一位是'\0',防止下面的while越界 for(int i = 0; i <= len; ++i){//初始化 str[i * 2 + 1] = '#'; str[i * 2 + 2] = s[i]; } len = 2 * len + 1; int pos = 0, maxlen = 1; p[0] = 1; for(int i = 2; i < len; ++i){ if(i < p[pos] + pos){ p[i] = min(pos + p[pos] - i, p[pos * 2 - i]); } else { p[i] = 1; } while(str[i - p[i]] == str[i + p[i]]){ ++p[i]; } if(i + p[i] > pos + p[pos]){ pos = i;//更新位置 } if(p[i] > maxlen){ maxlen = p[i];//更新结果 } } return maxlen - 1;}char s[maxn], str[maxn * 2];int p[maxn * 2];int main(){ while(~scanf("%s", s)){ printf("%d\n", manacher(s, str, p)); } return 0;}
阅读全文
0 0
- hdu3068(最长回文manacher)
- Manacher(hdu3068最长回文)
- hdu3068 最长回文(manacher)
- HDU3068 最长回文(manacher)
- 【HDU3068】最长回文【manacher】
- HDU3068 最长回文 manacher
- 【HDU3068】最长回文【Manacher】
- 最长回文 hdu3068 manacher
- Manacher HDU3068 最长回文
- HDU3068[最长回文]--Manacher
- hdu3068 最长回文(manacher 算法)
- hdu3068最长回文(manacher算法)
- HDU3068 最长回文(Manacher算法)
- HDU3068 最长回文(Manacher算法)
- hdu3068 最长回文串 (manacher)
- hdu3068 最长回文(Manacher模板)
- HDU3068-最长回文(Manacher算法)
- HDU3068最长回文 (Manacher模板)
- 使用google搜索自己在csdn写的博客
- java IO笔记(InputStream/OutputSteram)
- itext 导出pdf 表格生成、目录生成、支持中文
- python第一次实现爬数据,不过还是不太懂其中的原理,只是拿过来就用了
- ZOJ1654 Place the Robots
- HDU3068 最长回文(manacher)
- /etc/crontab文件和crontab -e命令区别
- HDU4966 GGS-DDU【最小树形图】
- 个人笔记3
- matlab---位于多个文件的函数之间的调用
- 招银面试汇总
- 未能加载文件或程序集 或它的某一个依赖项。试图加载格式不正确的程序。问题解决
- 关于触发器
- REPL module