[题目大意]:给定一个字符串,求到哪一位时的字串是前几位循环组成的,并求出循环次数。
思路:求每个前缀的最小循环周:从i到n枚举len,如果len%(len-next[len])==0,则这个前缀是由循环节组成的,且循环次数为len/(len-next[len])//len为当前i的值,next[len]为当前j的值。
#include <stdio.h> #include <string.h> #include <stdlib.h> char a[1000001]; int next[1000001]; int n; void  Getnext() {
   
int i=0;
   
int j=-1;
  
 next[0]=-1;
 
while(i<n)     {
    
    if(j==-1||a[i]==a[j])
   
    {
           
i++;
        
    j++;
          
  next[i]=j;
        
    if(i%(i-next[i])==0&&i/(i-next[i])>1)          {
              
  printf("%d %d\n",i,i/(i-next[i]));
     
       }
      
  }
     
   else j=next[j];
 
   } } int main() {
   
int k=0;
   
  while(scanf("%d",&n)!=EOF)
 
   {
        
k++;
        
if(n==0) break;
      
   getchar();
      
   for(int i=0;i<n;i++)
     
       scanf("%c",&a[i]);
      
    printf("Test case #%d\n",k);
    
     Getnext();
       
  printf("\n");
   
  }
  
  return 0; }

Period(sdut2476)的更多相关文章

  1. TCP Provider The semaphore timeout period has expired

    我们一数据库服务器上有个作业最近几天偶尔会遇到下面错误(敏感信息已做处理),主要是报"TCP Provider: The semaphore timeout period has expir ...

  2. SSRS 2008 R2 错误:Timeout expired. The timeout period

    今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred with ...

  3. Clock Skew , Clock Uncertainty和 Period

    本文将介绍FPGA中和时钟有关的相关概念,阅读本文前需要对时序收敛的基本概念和建立.保持关系有一定了解,这些内容可以在时序收敛:基本概念,建立时间和保持时间(setup time 和 hold tim ...

  4. HDU 5908 Abelian Period(暴力+想法题)

    传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...

  5. Match:Period(POJ 1961)

    Period 题目大意:给定一个字符串,要你找到前缀重复了多少次 思路,就是kmp的next数组的简单应用,不要修正next的距离就好了,直接就可以跳转了 PS:喝了点酒用递归实现除法和取余了...结 ...

  6. cargo failed to finish deploying within the timeout period [120000]

    cargo插件,报错:failed to finish deploying within the timeout period [120000] 解决方法:配置timeout为0 <plugin ...

  7. Date get period

    /** * get period for last year * @param time * @return */ public static DatePeriodDTO getLastYear(lo ...

  8. Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

    今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...

  9. POJ 1961 Period( KMP )*

    Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...

随机推荐

  1. springbatch---->springbatch的使用(六)

    前面的例子step都是线性的流程,这里我们提供一个非线性的流程,也就是根据不同的状态做不同的流程step处理.万一有天悔恨变得太现实太世故太麻木,说不定能从回忆中重拾随兴飞翔. step非线性的流程 ...

  2. Makefile eval函数

    https://www.cnblogs.com/gaojian/archive/2012/10/04/2711494.html对 makefile 中 eval 函数的学习体会 http://blog ...

  3. gradle-4.1-all.zip

    1. https://services.gradle.org/distributions/ https://services.gradle.org/distributions/gradle-4.1-a ...

  4. shell脚本技巧记录

    2014/4/9 shell脚本变量处理: ${varible##*string} //从左向右截取最后一个string后的字符串 ${varible#*string} //从左向右截取第一个stri ...

  5. oracle dblink 查询 tns:无法解析指定的连接标识符

    问题情景是这样的:我在数据库服务器(windows server 2008r2 ,64bit)oracle(11gr2,64bit)中通过dblink连接到另外一台服务器(hp-ux)的oracle( ...

  6. Xcode 6 下添加pch头文件

    没错了,Xcode 6 有着许多坑,例如新建的工程里没有默认的pch文件,当然本质上应该是为了提高编译的速度,但却让开发略微有点不方便. 话不多说,其实新建很简单 1.先新建一个PCH文件 2.设置头 ...

  7. Scikit-Learn实战KNN

    Scikit-Learn总结 Scikit-Learn(基于Python的工具包) 1.是一个基于Numpy,Scipy,Matplotlib的开源机器学习工具包. 2.该包于2007年发起,基本功能 ...

  8. Codeforces 838B - Diverging Directions - [DFS序+线段树]

    题目链接:http://codeforces.com/problemset/problem/838/B You are given a directed weighted graph with n n ...

  9. 蓝桥杯 - 数字排列(今有7对数字) - [两种不同的DFS思路]

    今有7对数字:两个1,两个2,两个3,...两个7,把它们排成一行.要求,两个1间有1个其它数字,两个2间有2个其它数字,以此类推,两个7之间有7个其它数字.如下就是一个符合要求的排列: 171264 ...

  10. 一套准确率高且效率高的分词、词性标注工具-thulac

    软件简介 THULAC(THU Lexical Analyzer for Chinese)由清华大学自然语言处理与社会人文计算实验室研制推出的一套中文词法分析工具包,具有中文分词和词性标注功能.THU ...