给出一个字符串,找出所有可以作为它循环节的子串长度

利用kmp的失配数组的性质,可以直接做

 #include<stdio.h>
#include<string.h> const int maxm=1e6+; char t[maxm];
int p[maxm]; int main(){
int m;
int cnt=;
while(scanf("%d",&m)!=EOF&&m){
int i,j;
scanf("%s",t);
p[]=p[]=;
for(i=;i<m;i++){
j=p[i];
while(j&&t[i]!=t[j])j=p[j];
p[i+]=t[i]==t[j]?j+:;
}
printf("Test case #%d\n",++cnt);
for(int i=;i<=m;++i){
if(p[i]!=&&!(p[i]%(i-p[i])))printf("%d %d\n",i,p[i]/(i-p[i])+);
}
printf("\n");
}
return ;
}

hdu1358 Period KMP的更多相关文章

  1. HDU1358 Period —— KMP 最小循环节

    题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  2. hdu1358 Period kmp求循环节

    链接 http://acm.hdu.edu.cn/showproblem.php?pid=1358 思路 当初shenben学长暑假讲过,当初太笨了,noip前几天才理解过来.. 我也没啥好说的 代码 ...

  3. poj1961 & hdu1358 Period【KMP】

    Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 20436   Accepted: 9961 Descripti ...

  4. [KMP求最小循环节][HDU1358][Period]

    题意 求所有循环次数大于1的前缀 的最大循环次数和前缀位置 解法 直接用KMP求最小循环节 当满足i%(i-next[i])&&next[i]!=0 前缀循环次数大于1 最小循环节是i ...

  5. kuangbin专题十六 KMP&&扩展KMP HDU1358 Period

    For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...

  6. HDU-1358 Period 字符串问题 KMP算法 求最小循环节

    题目链接:https://cn.vjudge.net/problem/HDU-1358 题意 给一个字符串,对下标大于2的元素,问有几个最小循环节 思路 对每个元素求一下minloop,模一下就好 提 ...

  7. HDU1358 Period 题解 KMP算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1358 题目大意:给你一个长度为 \(n\) 的字符串 \(s\) ,那么它有 \(n\) 个前缀. 对 ...

  8. POJ 1961 Period( KMP )*

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

  9. hdu oj Period (kmp的应用)

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

随机推荐

  1. jquery for&&each的用法

    var arr=['姚明','易建联','张继科']: each&&for用法 $.each(arr,function(index,value){ document.write(ind ...

  2. linux nginx 安装防火墙ngx_lua_waf

    ngx_lua_waf是一款开源的 基于 ngx_lua的 web应用防火墙 github地址是  https://github.com/loveshell/ngx_lua_waf 安装流程如下 1 ...

  3. day2-python工具的选择使用

    Python 编辑工具的选择 在Python的交互式命令行写程序,好处是一下就能得到结果,坏处是没法保存,下次还想运行的时候,还得再敲一遍. 所以,实际开发的时候,我们总是使用一个编辑器来写代码,写完 ...

  4. Mysql 数据库意向锁意义

    锁:对 “某种范围” 的数据上 “某种锁”1.“某种范围”:行.表 2.“某种锁”2.1 共享锁Shared Locks(S锁)1.兼容性:加了S锁的记录,允许其他事务再加S锁,不允许其他事务再加X锁 ...

  5. openpyxl读取Excel数据

    #! Python3 #-*- coding:utf8 -*- import openpyxl #载入表格内容 wb=openpyxl.load_workbook('e:\\work\\newFile ...

  6. [rancher-net]

    ip rule命令 rancher网络全解读 arp命令查询 rancher managed network 实践 docker自定义网桥 iptables增删改查 shell脚本调试技术

  7. Effective Java Chapter4 Classes and Interface

    MInimize the accessibility of classes and members 这个叫做所谓的 information hiding ,这么做在于让程序耦合度更低,增加程序的健壮性 ...

  8. nodejs .http模块, cheerio模块 实现 小爬虫.

    代码: var http = require("http"); var cheerio = require("cheerio"); var url = 'htt ...

  9. ios 汽车品牌展示案例

    汽车组模型 // ZQRGroup.h #import <Foundation/Foundation.h> @interface ZQRGroup : NSObject /** *组标题 ...

  10. ubantu 安装nginx HTTP反向代理服务器

    Nginx发音的“engine x”是一个免费的开源高性能HTTP和反向代理服务器,负责处理互联网上一些最大的网站的负载. 本教程将概述在Ubuntu 18.04机器上安装和管理Nginx的步骤. 安 ...