[题目大意]:给定一个字符串,求到哪一位时的字串是前几位循环组成的,并求出循环次数。
思路:求每个前缀的最小循环周:从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. Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

    改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "use ...

  2. Android调试技巧

    转自:http://gityuan.com/2017/07/11/android_debug/ 一. 获取Trace 调用栈信息(Trace)是分析异常经常使用的,这里简单划分两类情况: 当前线程Tr ...

  3. POJ 3579 Median(二分答案)

    Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11599 Accepted: 4112 Description G ...

  4. VUE单独页面body css设置

    使用created周期用JS来处理BODY的样式 export default { beforeCreate: function () { document.getElementsByTagName( ...

  5. 【转】Android四大基本组件介绍与生命周期

    转自:http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html Android四大基本组件分别是Activity,Serv ...

  6. wps插件开发中com组件权限

    需要对wps写一个小的插件,也就是几行代码的事情,但却碰到了一个坑 wps中的com组件的调用和MSoffice非常的相似,几乎只需要把包的头修改一下就可以用了. 比如开发wps文档的插件,需要引用 ...

  7. python nose测试框架全面介绍一

    一.简介      nose 是python自带框架unttest的扩展,使测试更简单高效:nose是一个开源的项目,可以在官网上下载源码 1.快速安装 有以下几中安装方式: easy_install ...

  8. windows下的C++与cuda编译器位置

    在windows下最常见的C++编译器为visual studio自带的编译器cl.exe 通常其所在目录为: C:\Program Files (x86)\Microsoft Visual Stud ...

  9. Twig---的使用

    使用Twig的参考文档: https://www.kancloud.cn/yunye/twig-cn/159454 Twig是一款灵活.快速.安全的PHP模板引擎. 示例: <?php echo ...

  10. 冒泡排序算法的 python 实现与 C 的比较

    昨天用c写了简单的冒泡排序算法之后,正好最近在学 python,也想试试用python实现一下. 总体感觉,对于这种简答的小程序,python 确实充分体现了他简洁,易懂的特点.写起来特别流畅,舒服. ...