[题目大意]:给定一个字符串,求到哪一位时的字串是前几位循环组成的,并求出循环次数。
思路:求每个前缀的最小循环周:从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. open-falcon之dashboard\portal说明.md

    dashboard 功能 为用户展示监控数据 配置文件 gunicorn.conf - workers,dashboard并发进程数 - bind,dashboard的http监听端口 - proc_ ...

  2. shell编程(一)

    迷迷糊糊中发现了一个学习shell的非常好的教程,从头到尾看了一下,等看完全忘记了,没办法只能记录下来,教程网址http://c.biancheng.net/cpp/view/6994.html 以前 ...

  3. 【VI】如何再执行上一个(历史)命令(已解决)

    输入命令提示符( : )+ 上下箭头(<Up/Down>键) 输入 :his 或者 :history 查看历史

  4. POP3协议分析

    http://m.blog.csdn.net/bripengandre/article/details/2192111 POP3协议分析 第1章.     POP3概述 POP3全称为Post Off ...

  5. 题目1010:A + B(字符串转数字)

    题目链接:http://ac.jobdu.com/problem.php?pid=1010 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  6. [原]openstack-kilo--issue(三) openstack-nova-issue-systemctl start openstack-nova-compute.service

    本博客已经添加"打赏"功能,"打赏"位置位于右边栏红色框中,感谢您赞助的咖啡. execute systemctl start openstack-nova-c ...

  7. linux各种版本下载地址

    本文转载地址:http://52199999.blog.51cto.com/740826/290179 觉得好大家给顶顶,先谢谢了!呵呵 首先提供两个镜像站:http://mirrors.sohu.c ...

  8. loop设备及losetup命令

    1. loop设备介绍 在类 UNIX 系统里,loop 设备是一种伪设备(pseudo-device),或者也可以说是仿真设备.它能使我们像块设备一样访问一个文件.在使用之前,一个 loop 设备必 ...

  9. 【转】python中json.loads与eval的区别

    JSON有两种结构: “名称/值”对的集合(A collection of name/value pairs).不同的语言中,它被理解为对象(object),纪录(record),结构(struct) ...

  10. java的HashSet 原理

    概括:HashSet 以HashMap为基础,判断HashSet 中元素是否存在和重复,先把该元素经过hashcode()等方法计算之后得到的值作为key值, 然后比较该key值是否存在和重复(把该元 ...