poj 2406 Power Strings kmp算法
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 27368 | Accepted: 11454 |
Description
empty string) and a^(n+1) = a*(a^n).
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
kmp算法里的make next函数就可以了,不过我今天还是没搞明白这个算法的原理,只能说暂时能写对这个算法
#include<stdio.h>
#include<string.h>
char str[1000];
int next[1000];
void make_next()
{
int i = 1, j = 0;
next[0] = -1;
while(str[i])
{
if(j == -1 || str[j] == str[i])
next[++i] = ++j;
else
j = next[j];
}
}
int main()
{
while(scanf("%s", str), str[0] + str[1] != '.')
{
make_next();
int i = strlen(str);
int len = i - next[i];
if(i % len == 0)
printf("%d\n",i / len);
else printf("1\n");
}
return 0;
}
poj 2406 Power Strings kmp算法的更多相关文章
- POJ 2406 Power Strings KMP算法之next数组的应用
题意:给一个字符串,求该串最多由多少个相同的子串相接而成. 思路:只要做过poj 1961之后,这道题就很简单了.poj 1961 详细题解传送门. 假设字符串的长度为len,如果 len % (le ...
- POJ 2406 Power Strings (KMP)
Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
- poj 2406 Power Strings(KMP变形)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28102 Accepted: 11755 D ...
- POJ 2406 - Power Strings - [KMP求最小循环节]
题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...
- POJ 2406 Power Strings KMP求周期
传送门 http://poj.org/problem?id=2406 题目就是求循环了几次. 记得如果每循环输出为1.... #include<cstdio> #include<cs ...
- POJ 2406 Power Strings KMP运用题解
本题是计算一个字符串能完整分成多少一模一样的子字符串. 原来是使用KMP的next数组计算出来的,一直都认为是能够利用next数组的.可是自己想了非常久没能这么简洁地总结出来,也仅仅能查查他人代码才恍 ...
- poj 2406 Power Strings KMP匹配
对于数组s[0~n-1],计算next[0~n](多计算一位). 考虑next[n],如果t=n-next[n],如果n%t==0,则t就是问题的解,否则解为1. 这样考虑: 比方字符串"a ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
随机推荐
- js移动焦点到最后
当输入框(input/textarea)获得焦点时,将焦点移动到最后,在某些情况下用户体验很好.网上的大部分方法都是针对IE浏览器的.代码如下: var el = document.getElem ...
- TKinter的常用组件
python提供了多个图形开发界面的库,几个常用Python GUI库如下: Tkinter: Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.T ...
- ios 获取屏幕的属性和宽度
app尺寸,去掉状态栏 CGRect r = [ UIScreen mainScreen ].applicationFrame; r=0,20,320,460 屏幕尺寸 CGRect rx = [ U ...
- tnsnames linux找的位置顺序
In Sue’s article, it states that SQLDeveloper looks for a tnsnames.ora in the following places in th ...
- Android中实现java与PHP服务器(基于新浪云免费云平台)http通信详解
Android中实现java与PHP服务器(基于新浪云免费云平台)http通信详解 (本文转自: http://blog.csdn.net/yinhaide/article/details/44756 ...
- Android 服务端开发之开发环境配置
Android 服务端开发之开发环境配置 这里是在Eclipse的基础上安装PhpEclipse插件方法,PHPEclipse是Eclipse的 一个用于开发PHP的插件.当然也可以采用Java开发a ...
- 客户端TortoiseSVN的安装及使用方法
一.客户端TortoiseSVN的安装 运行TortoiseSVN程序,点击Next,下面的截图顺序即为安装步骤: 图1: 图2: 图3: 图4: 点击Finish按钮后会提示重启系统,其实不重启也没 ...
- oracle数据库数据导出和导入
oracle的客户端里面的bin下面有两个可执行文件,名称分别为exp.exe和imp.exe. 他俩的用途就是导出和导入数据用的. 全库 导出:exp 用户名/密码@数据库名 full=y file ...
- 在网页标题栏上和收藏夹显示网站logo
第一步,准备一个图标制作软件. 首先您必须了解所谓的图标(Icon)是一种特殊的图形文件格式,它是以.ico 作为扩展名.普通的图像设计软件无法使用这种格式,所以您需要到下载一个ico图标工具,本站常 ...
- FFTW简介及使用
http://fftw.org/ FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) i ...