acwing 141. 周期

简介: acwing 141. 周期

141. 周期 - AcWing题库

#include<iostream>
#include<algorithm>
#include<cstring>
 
using namespace std ;
const int N = 1e6 +10 ;
int n , m ;
char s[N] ;
int ne[N] ;
void get_ne(){
  memset(ne,0,sizeof(ne)) ;
  for(int i = 2 , j = 0 ; i <= n ; i ++){
    while(j && s[i] != s[j+1]) j = ne[j] ;
    if(s[i] == s[j+1]) j ++ ;
    ne[i] = j ; 
  }
  
}
int main(){
  int t = 0 ;
  while(cin >> n , n ){
    cin >> s+ 1;
    get_ne() ;
    printf("Test case #%d\n",++t) ;
    for(int i = 2 ; i <=n ;i ++){
      if(i %(i-ne[i]) == 0 && i /(i-ne[i]) > 1)
        printf("%d %d\n",i , i /(i-ne[i])) ;
    }
    cout << endl ;
  }
}
目录
相关文章
AcWing 3498. 日期差值(每日一题)
AcWing 3498. 日期差值(每日一题)
|
9月前
春节每日一题~(自除数,除自身以外的数的乘积)
春节每日一题~(自除数,除自身以外的数的乘积)
41 1
|
9月前
|
测试技术 C++
[C++/PTA] 计算时间相减
[C++/PTA] 计算时间相减
68 0
【寒假每日一题】AcWing 3400. 统计次数(补)
目录 一、题目 1、原题链接 2、题目描述 二、解题报告 1、思路分析 2、时间复杂度 3、代码详解
63 0
|
人工智能 算法 测试技术
【寒假每日一题】AcWing 4644. 求和(补)
目录 一、题目 1、原题链接 2、题目描述 二、解题报告 1、思路分析 2、时间复杂度 3、代码详解
91 0
|
测试技术
【寒假每日一题】AcWing 4653. 数位排序(补)
目录 一、题目 1、原题链接 2、题目描述 二、解题报告 1、思路分析 2、时间复杂度 3、代码详解 三、知识风暴 关于pair
113 0
|
人工智能 测试技术
【寒假每日一题】AcWing 4655. 重新排序(补)
目录 一、题目 1、原题链接 2、题目描述 二、解题报告 1、思路分析 2、时间复杂度 3、代码详解 三、知识风暴 1、前缀和与差分 2、排序不等式
68 0
数学题-零点式转换为一般式Know your Aliens
题目描述 Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them from real humans.
122 0
数学题-零点式转换为一般式Know your Aliens
干草堆——acwing算法题第二天
干草堆——acwing算法题第二天
干草堆——acwing算法题第二天