poj 1961 Period KMP
2013-12-03 15:32
441 查看
题目大意:给定字符串S,求其前n位所组成的字符串,其最小单元重复的次数。是上一篇的拓展;
上一篇
上一篇
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 1000010; int next[MAXN]; void Get_Next(char* str) { int i = 0, j = -1; next[0] = -1; int len = strlen(str); while(i < len) { if(j == -1 || str[i] == str[j]) { ++i; ++j; next[i] = j; } else j = next[j]; } } int main() { int kcase = 1; int length; char str[MAXN]; while(cin>>length) { if(length == 0) break; cin>>str; Get_Next(str); int i = 2; int len = strlen(str); cout<<"Test case #"<<kcase++<<endl; while(i <= len ) { if(i%(i - next[i]) == 0) if(i/(i-next[i]) > 1)//别忘了题目要求k>1 cout<<i<<" "<<i/(i-next[i])<<endl; ++i; } cout<<endl; } return 0; }
相关文章推荐
- 创建 XXXXXXXX 的配置节处理程序时出错: 请求失败
- Flex基础知识
- VS2010 ReportViewer导出文件下载保存不能识别文件类型
- Winform(C#.NET)自动更新组件的使用及部分功能实现(一点改进功能)
- 免费iOS第三方推送工具Urban Airship使用教程
- HDU3113(工科数学分析之分解)
- ibm websphere portal8.0 url 跳转保持当前语言环境配置
- Redirect 原理
- pajek 指标计算
- MySQL表分区的使用
- 最长上升子序列(Longest Increasing Subsequence)
- magento cron 配置
- 用Nmap工具查找Downadup/Conficker的蠕虫病毒源
- 一周入门FPGA
- 解决spring.handlers spring.schemas spring.tooling 被覆盖问题,而出现Spring 3.0: Unable to locate Spring Namespa
- c3p0配置解析
- ubuntu下如何安装vmware tool?
- 解决VS2010中CString 转char*的问题
- 每日英语:How to Solve India's Huge Food Wastage
- hadoop2.2编译