poj 1961
来源:互联网 发布:neu的数据分析 编辑:程序博客网 时间:2024/05/17 06:56
循环节是i-next[i];
第一次超时是没直接用n,多用了strlen;
代码如下
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;int nextt[1000005];char s[1000005];int n;void Pre_next(char s[]){int k,j;j=0;nextt[0]=k=-1;while(j<n){if(k==-1||s[j]==s[k]) nextt[++j]=++k;else k=nextt[k];} } int main(){int cnt=0;while(scanf("%d",&n)){if(n==0) break;scanf("%s",s);Pre_next(s);printf("Test case #%d\n",++cnt);for(int i=1;i<=n;i++){int len=i-nextt[i];if(i!=len&&i%len==0)printf("%d %d\n",i,i/len);}printf("\n");}}
阅读全文
0 0
- poj 1961
- POJ 1961
- 【POJ 1961】
- poj 1961
- POJ 1961
- Poj 1961
- POJ 1961
- POJ 1961
- POJ 1961
- poj 1961
- (KMP) poj POJ 1961 Period
- kmp算法练习 poj 1226 poj 1961
- POJ 1961 Period
- poj 1961 Period
- POJ 1961 Period
- poj 1961 Period
- poj 1961(KMP)
- POJ 1961 KMP
- HLS协议全解
- 高精度乘法(正整数)
- 归并排序
- 关于 KMP next 数组的应用
- 影响公众试听,阻碍社会发展!
- poj 1961
- Python如何在dic(字典)里面添加dic(字典) 附dic基础知识
- 编程小白的第一本python入门书
- 【机器人学】机器人开源项目KDL源码学习:(8)KDL的精髓
- Open vSwitch(OVS)相关问题
- Android Studio教程从入门到精通
- LintCode-----12.带最小值操作的栈
- 快速排序
- bugku sql注入2