http://poj.org/problem?id=1961

题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数。

思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是KMP。

#include <string.h>
#include <stdio.h>
#include <iostream> using namespace std ; const int maxn = ; char ch[maxn] ;
int next[maxn] ; int main()
{
int n ;
int test = ;
while(scanf("%d%*c",&n)!=EOF)
{
if(n == ) break ;
scanf("%s",ch) ;
printf("Test case #%d\n",test) ;
test++ ;
int i = , j = - ;
next[] = - ;
while(i < n )
{
if(j == - || ch[i] == ch[j])
next[++i] = ++j ;
else
j = next[j] ;
}
int len ;
for(int k = ; k <= n ; k++)
{
len = k - next[k] ;
if(k != len && k % len == )
printf("%d %d\n",k,k / len) ;
}
printf("\n") ;
}
return ;
}

POJ 1961 Period(KMP)的更多相关文章

  1. LA 3026 && POJ 1961 Period (KMP算法)

    题意:给定一个长度为n字符串s,求它每个前缀的最短循环节.也就是对于每个i(2<=i<=n),求一个最大整数k>1(如果存在),使得s的前i个字符组成的前缀是某个字符串重复得k次得到 ...

  2. poj 1961 Period(KMP训练指南例题)

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 11356   Accepted: 5279 Descripti ...

  3. POJ 1961 2406 (KMP,最小循环节,循环周期)

    关于KMP的最短循环节.循环周期,请戳: http://www.cnblogs.com/chenxiwenruo/p/3546457.html (KMP模板,最小循环节) POJ 2406  Powe ...

  4. Period(kmp)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. HDU - 1358 - Period (KMP)

    Period Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  6. poj 3461 Oulipo(KMP)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49378   Accepted: 19617 Descript ...

  7. KMP POJ 1961 Period

    题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...

  8. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  9. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

随机推荐

  1. 大数据架构:flume-ng+Kafka+Storm+HDFS 实时系统组合

    http://www.aboutyun.com/thread-6855-1-1.html 个人观点:大数据我们都知道hadoop,但并不都是hadoop.我们该如何构建大数据库项目.对于离线处理,ha ...

  2. 无责任比较thrift vs protocol buffers

    http://blog.csdn.net/socoolfj/article/details/3855007 最新版本的Hadoop代码中已经默认了Protocol buffer作为RPC的默认实现,原 ...

  3. Activiti初学者教程

    http://wenku.baidu.com/view/bb7364ad4693daef5ff73d32.html 1. 初识Activiti 1.1. 工作流与工作流引擎 工作流(workflow) ...

  4. Delphi - 在ListView中添加一个进度条

    // 相关定义 Type TListData = Record FileName: String; Percent: Integer; End; PListData = ^TListData; // ...

  5. VS2012无法创建项目:未找到与约束……匹配的导出

    故障情况:7月10号后用VS2012创建项目时,弹出如下对话框,无法创建新项目: 而后经网络搜索确定是7月10号更新了系统补丁后造成的 解决方案: 1.卸载这两个补丁后重启电脑: 2.到http:// ...

  6. ThreadLocal 设计模式浅谈

    部分代码:ThreadLocal中 的get方法, 获得的是当前线程相关的对象 /** * Returns the value in the current thread's copy of this ...

  7. 从V$SQL_PLAN中FORMAT执行计划

    10G版本 select sql_id from v$sqlarea where sql_text like'%xxx%'; select  * from v$sql_plan where sql_i ...

  8. 2 JavaScript应用开发实践指南

    JavaScript 语言在浏览器中的运用 HTTP请求,加载HTML后根据内容加载CSS等,大部分浏览器默认2个下载链接. HTML元素要尽可能简洁,不需要将Table元素变成多个div, css代 ...

  9. .net远程连接oracle数据库不用安装oracle客户端的方法

    .net远程连接oracle数据库不用安装oracle客户端的方法步骤: 1.添加Sytem.Data.OracleClient命名空间. 2.连接时需要ConnectionString字符串,出现在 ...

  10. lucene4.0 基于smb文件服务器的全文检索

    使用lucene 4.0版本的全文检索 所需要的jar包  网速太慢,下次有空再把jar传上来 1.FileIndex  建立索引,查询,删除,更新 package com.strongit.tool ...