POJ 2406 Power Strings (kmp求周期)
来源:互联网 发布:易语言编程 编辑:程序博客网 时间:2024/05/16 19:10
题意:
求串的循环次数
分析:
求出最小周期=n−nxt[n],判断下整除然后就好了
代码:
//// Created by TaoSama on 2015-10-28// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, nxt[N];char s[N];void getNxt() { nxt[0] = -1; int i = 0, j = -1; while(i < n) { if(j == -1 || s[i] == s[j]) nxt[++i] = ++j; else j = nxt[j]; }}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%s", s) == 1 && *s != '.') { n = strlen(s); getNxt(); int cycle = n - nxt[n]; int ans = n % cycle ? 1 : n / cycle; printf("%d\n", ans); } return 0;}
0 0
- POJ 2406 Power Strings KMP求周期
- POJ 2406 Power Strings (kmp求周期)
- [KMP求最小周期]POJ 2406 Power Strings
- POJ--2406Power Strings+KMP求字符串最小周期
- POJ 2406 Power Strings(KMP找周期)
- poj 2406 Power Strings ( fail 数组求周期)
- poj_2406 Power Strings(KMP求周期子串)
- poj2406--Power Strings+KMP求周期
- POJ 2406 Power Strings 求连续重复字串(kmp)
- poj 2406 Power Strings(KMP求循环次数)
- POJ 2406 Power Strings(KMP求最小循环节)
- 【POJ 2406】 Power Strings(KMP求循环节)
- poj 2406:Power Strings(KMP)
- poj 2406 Power Strings(kmp算法)
- POJ 2406 Power Strings(kmp)
- POJ 题目2406 Power Strings(KMP)
- POJ 2406 Power Strings(kmp)
- poj 2406 Power Strings (KMp)
- AndroidTest
- MVC框架
- C++ main函数 argc,argv传递参数的含义
- 【LeetCode从零单刷】Symmetric Tree
- Java jdk配置
- POJ 2406 Power Strings (kmp求周期)
- Java鼠标监听(单击、双击、滑轮)
- Linux中环境变量文件及配置
- stderr和stdout详细解说
- OC第四天之 NSString
- 有趣的数学--Catalan Number
- hdu2535 Vote
- Java 工程结构管理 Build Path
- MyBatis之理论篇