题目链接:uva10298 - Power
Strings
题目大意:给出一个字符串,求出该字符串是由几个最小循环节组成的。
解题思路:KMP, n-next[n]即为最小循环节。
#include <stdio.h>
#include <string.h>
const int N = 1000005;
int n, next[N];
char s[N];
void getNext () {
int p = 0;
n = strlen(s+1);
for (int i = 2; i <= n; i++) {
while (p > 0 && s[p+1] != s[i])
p = next[p];
if (s[p+1] == s[i])
p++;
next[i] = p;
}
}
int main () {
while (scanf("%s", s+1) == 1 && strcmp(s+1, ".") ) {
getNext ();
int k = n - next[n];
printf("%d\n", n%k == 0 ? n/k : 1);
}
return 0;
}
分享到:
相关推荐
北大POJ3096-Surprising Strings 解题报告+AC代码
pku acm 2406 Power Strings代码 kmp算法。解题报告:http://blog.csdn.net/china8848
Pratt: Fast Pattern Matching in Strings. SIAM Journal of Computing 6, 2, 323-350 (1977) [2] http://www.cse.iitk.ac.in/users/dsrkg/cs210/applets/strMatching/KMPMatching/kmp.html [3] ...
分配字符串模块3 =字符串和函数在本练习中,学生将在示例的帮助下学习C编程中的字符串并学习声明它们,对其进行初始化并将其用于各种I / O操作,并且将向学生介绍函数(用户定义函数和标准库函数) )在C编程中。...
正在安装酿造去做brew install xcode-dead-strings从来源克隆此项目并运行swift build -c release技术支持 Swift "Regular Strings" """Multiline Strings""" #"Raw Strings"# Objective-C(++) 信息列表键例子按...
The book is a general, rigorous text on deterministic algorithms that operate on strings, and sequences. It covers the full spectrum of string algorithms from clasical computer science to modern ...
介绍了基于树和序列的一些算法,比较详细和权威,讲得很好,全英文版的
npm i gulp-es6-template-strings --save 用法 有关更多用例,请参见 var gulp = require ( 'gulp' ) var template = require ( 'gulp-es6-template-strings' ) gulp . src ( './src/*.{html,txt}' ) . pipe ( ...
Windows Forms - Use Format Codes to Format Data in Strings
The book is a general, rigorous text on deterministic algorithms that operate on strings, and sequences. It covers the full spectrum of string algorithms from clasical computer science to modern ...
贝岭的matlab的代码Exo-79-Les-Strings-2 对于这些 exos,您将始终使用相同的变量! 创建一个包含文本的变量:It is beautiful my apple! 外 1 Récupérez le paragraphe #index-pomme et donnez lui comme valeur,...
The book is a general, rigorous text on deterministic algorithms that operate on strings, and sequences. It covers the full spectrum of string algorithms from clasical computer science to modern ...
Java Methods-Strings.ppt
hackerrank_Strings Hackerrank中Category Algorithm->Strings下问题的解决方法
Android笔记(二十九):利用python自动生成多语言文章内用到的脚本源码 原文地址:https://blog.csdn.net/weixin_40855673/article/details/132819008
header File in c++ String use in C++
c-sharp-search-strings
home-work-Methods-of-strings
分配字符串模块3 =字符串和函数在本练习中,学生将学习C编程中的字符串,并学习如何声明它们,对其进行初始化,并在示例的帮助下将其用于各种I / O操作,并将向学生介绍函数(用户定义函数和标准库函数) )在C编程...