hdu 1358 KMP的next数据运用
由于next[i]保存的是前i-1个字符中最大的重复子序列,那么i-next[i]就是循环节。
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int next[];
void getnext(char *str)
{
int j,k;
memset(next,,sizeof(next));
j=;
k=-;
next[]=-;
while(str[j])
{
if(k==- || str[j]==str[k])
next[++j]=++k;
else
k=next[k];
}
}
int main()
{
int n,i,j;
int Case=;
char str[];
while(scanf("%d",&n),n)
{
scanf("%s",&str);
getnext(str);
printf("Test case #%d\n",++Case);
for(i=;i<=n;i++)
{
int x=i/(i-next[i]);
if(i%(i-next[i])==&&x>)
printf("%d %d\n",i,x);
}
printf("\n");
}
return ;
}
hdu 1358 KMP的next数据运用的更多相关文章
- 【无聊放个模板系列】HDU 1358 KMP
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #inc ...
- hdu poj KMP简单题目总结
hdu 3336 题意:输入一个字符串求每个前缀在串中出现的次数和 sol:只要稍微理解下next 数组的含义就知道只要把每个有意义的next值得个数加起来即可 PS:网上有dp解法orz,dp[i] ...
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- Cyclic Nacklace HDU 3746 KMP 循环节
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len ...
- HDU 1358 Period KMP
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1358 求周期问题,简单KMP—— AC代码: #include <iostream> # ...
- HDU 3746 - Cyclic Nacklace & HDU 1358 - Period - [KMP求最小循环节]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- (KMP 根据循环节来计算)Period -- hdu -- 1358
http://acm.hdu.edu.cn/showproblem.php?pid=1358 Period Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 1358 Period(KMP计算周期)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一串字符串,判断字符串的前缀是否由某些字符串多次重复而构成. 也就是,从第1个字母 ...
- KMP + 求最小循环节 --- HDU 1358 Period
Period Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1358 Mean: 给你一个字符串,让你从第二个字符开始判断当前长度 ...
随机推荐
- rsync 无密码传输文件
最近机器迁移,需要备份文件,但各个机器间不能穿梭,即无法通过scp来传输文件, 在运维的建议下,选用了rsync作为传输的工具. 默认情况Ubuntu安装了rsync服务,但在/etc下没有配置文件, ...
- Spring EL regular expression example
Spring EL supports regular expression using a simple keyword "matches", which is really aw ...
- ISP与IAP的区别
转: ISP(In-System Programming)在系统可编程,指电路板上的空白器件可以编程写入最终用户代码, 而不需要从电路板上取下器件,已经编程的器件也可以用ISP方式擦除或再编程.IAP ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- Serializable 序列化为文件
package test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...
- java functional syntax overview
Defining a Functional Interface @FunctionalInterface public interface TailCall<T> { TailCall&l ...
- Python if..else
200 ? "200px" : this.width)!important;} --> 一.介绍 1.完整形式 if <条件判断1>: <执行1> e ...
- python字符串相关的函数
有些是字符串对象的方法,有些是内建库的方法 split分割字符串 find 查找字符串 for c in str: 遍历字符串 len 获取字符串长度 int 将字符串转换成int str ...
- SQLite多线程写锁文件解决方案
在sqlite编程中多线程同时写时会出现异常,我写了个类来解决这个问题. 思路很简单,就是在开始写操作时,记下写操作的托管线程id,表示目前有线程正在做写操作:其他线程来写时,需要先检测是否有进程正在 ...
- VHD_Update_diskpart
###################功能说明########################该脚本用来对离线VHD文件更新,导入系统补丁############################### ...