[POJ1961] Period
来源:互联网 发布:unity3d模型资源百度云 编辑:程序博客网 时间:2024/06/13 21:53
题目描述
给你若干个字符串,对于每个字符串,分解成N个前缀子串。对于每个前缀子串,看其是由几个重复子串构成的。也就是说,对于字符串S的前i (2 <= i <= N)个字符能否用子串A表示为AK的形式,要求计算子串A的长度和循环周期k(k>1)的值。例如aabaabaab,前缀子串aa,是由2个a构成的;前缀子串aabaab,是由2个aab构成的,前缀子串aabaabaab是由,3个aab构成的。
输入格式
输入文件包含多组测试数据,每组测试数据共计两行,第一行为一个整数N(2<=N<=1000000),表示字符串S的长度,第二行为字符串S,文件最后一行以一个0最为结束。
输出格式
对于每组测试数据,第一行输出”Test case #” 和该测试数据是第几组,接下来若干行,每行为子串A的长度和循环周期k (k>1)的值,按照前缀长度递增的顺序输出。每组数据结束输出一空行。
样例数据
样例输入
3
aaa
12
aabaabaabaab
0
样例输出
Test case #1
2 2
3 3
Test case #2
2 2
6 2
9 3
12 4
题目分析
枚举子串,其余同poj2406
源代码
#include<algorithm>#include<iostream>#include<iomanip>#include<cstring>#include<cstdlib>#include<vector>#include<cstdio>#include<cmath>#include<queue>using namespace std;inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj;}string s;int len,Next[1000005],cnt=0;void Get_Next(string s) { int i=1,j=0; Next[1]=0; while(i<=len) if(j==0||s[i]==s[j])Next[++i]=++j; else j=Next[j];}int main() { ios::sync_with_stdio(false); while(true) { cin>>len; if(len==0)break; cin>>s; s=' '+s; Get_Next(s); cnt++; printf("Test case #%d\n",cnt); for(int i=1; i<=len; i++) if(i%(i+1-Next[i+1])==0&&i/(i+1-Next[i+1])>1)printf("%d %d\n",i,i/(i+1-Next[i+1])); putchar('\n'); } return 0;}
0 0
- poj1961 Period
- poj1961 Period
- poj1961 Period
- poj1961 Period
- poj1961 Period
- POJ1961-Period
- [POJ1961] Period
- poj1961 period
- Period||POJ1961
- 【KMP】 poj1961 Period
- poj1961 Period----KMP
- poj1961 Period (KMP)
- KMP POJ1961 Period
- [POJ1961] Period/[NKOI2201] 周期
- [POJ1961]Period(KMP)
- poj1961 Period(KMP)
- POJ1961 Period(KMP)
- poj1961——Period
- 链表的基本操作
- configure intel C compiler / eclipse development environment
- 手机实现远程桌面控制
- 并查集解树的最近公共祖先问题
- 2016年度总结
- [POJ1961] Period
- 使用亚马逊云服务平台aws 搭建 shadowsocks
- LVS配置命令理解1
- Linux中环境变量文件及配置
- 信号阻塞未达pending原理机制讲解
- SQL中Case的使用方法
- cf623a
- 信号未达代码讲解
- [POJ2752] Seek the Name,Seek the Fame