POJ 2406 Power String(KMP)
来源:互联网 发布:成都美工平均工资 编辑:程序博客网 时间:2024/04/30 11:35
解题思路:
依旧是利用next数组的性质,m % (m - next[m]) == 0;
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <queue>#include <stack>#define LL long long#define FOR(i,x,y) for(int i=x;i<=y;i++)using namespace std;const int maxn = 1000000 + 10;char s[maxn];int next[maxn];int main(){ while(scanf("%s", s)!=EOF) { if(strcmp(s,".") == 0) break; int m = strlen(s); next[0] = 0; next[1] = 0; for(int i=1;i<m;i++) { int j = next[i]; while(j && s[i] != s[j]) j = next[j]; next[i+1] = (s[i] == s[j]) ? j + 1 : 0; } int ans = 1; if(next[m] > 0 && m % (m - next[m]) == 0) ans = m / (m - next[m]); printf("%d\n", ans); } return 0;}
0 0
- POJ 2406 Power String(KMP)
- poj 2406 Power String (KMP)
- poj 2406 power string(KMP)
- POJ 2406 Power String(KMP)
- POJ 2406 Power String
- POJ 2406 - Power String
- poj 2406 Power Strings---kmp
- POJ 2406 Power Strings KMP
- poj-2406-Power Strings-kmp
- POJ-2406 Power Strings KMP
- Power Strings - POJ 2406 KMP
- poj 2406 Power Strings kmp
- POJ 2406-Power Strings (KMP)
- 【KMP】 POJ 2406 Power Strings
- poj 2406 Power Strings KMP
- POJ 2406 Power Strings KMP
- poj 2406 Power Strings KMP
- poj 2406 Power Strings (KMP)
- Java实现:在二元树中找出和为某一值的所有路径
- 大设计系列:异或运算
- C语言之运算符
- 一个权贵家族的覆灭样本
- Android学习笔记 - Intent
- POJ 2406 Power String(KMP)
- ubuntu下安装Apache+PHP+Mysql
- Android学习笔记 - Service
- hdu 2516 取石子游戏 博弈论---斐波那契额博弈
- C语言之循环语句
- 【数据库系统概论】绪论----数据库系统概论(二)
- Android XML布局与View之间的转换
- python scrapy运行报错解决
- Xtrabackup安装及使用