POJ 2752 同一个串的前后串
poj 前后 同一个
2023-09-11 14:13:59 时间
题解东北赛回来再补
#include<stdio.h>
#include<string.h>
int next[500000];
int ans[500000];
char str[500000];
void get_next(int m)
{
int j ,k;
j = 0 ,k = -1;
next[0] = -1;
while(j < m)
{
if(k == -1 || str[k] == str[j])
next[++j] = ++k;
else k = next[k];
}
}
int main ()
{
while(~scanf("%s" ,str))
{
int m = strlen(str);
get_next(m);
int an = 0;
ans[++an] = m;
while(next[ans[an]])
{
int tmp = next[ans[an]];
ans[++an] = tmp;
}
for(int i = an ;i >= 1 ;i --)
if(i == an) printf("%d" ,ans[i]);
else printf(" %d" ,ans[i]);
printf("\n");
}
return 0;
}
相关文章
- poj 3069 Saruman's Army 贪心模拟
- poj 3617 Best Cow Line 贪心模拟
- poj 1027 Ignatius and the Princess II全排列
- poj 1330 Nearest Common Ancestors 求最近祖先节点
- poj分类
- poj 2594Treasure Exploration(有向图路径可相交的最小路径覆盖)
- [POJ] DNA Sorting
- POJ题目1947 Rebuilding Roads(树形dp)
- 如何在北京大学poj上面在线刷题
- POJ 3632 Optimal Parking(简单题)
- poj 1664 把平果
- POJ 3013 Big Christmas Tree(最短Dijkstra+优先级队列优化,SPFA)
- POJ 2524 Ubiquitous Religions
- POJ 1927 Area in Triangle(计算几何)
- POJ 3253 Fence Repair(哈夫曼树)
- poj 1611 The Suspects(并查集)
- poj 2482 Stars in Your Window(扫描线)
- Chapter06-Phylogenetic Trees Inherited(POJ 2414)(减少国家DP)