poj 1961 Period
Time Limit: 3000MS | Memory Limit: 30000K | |
Description
Input
number zero on it.
Output
Sample Input
3
aaa
12
aabaabaabaab
0
Sample Output
Test case #1
2 2
3 3 Test case #2
2 2
6 2
9 3
12 4
Source
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,t;
char s[];
int f[];
void getnext()
{
for(int i=;i<n;i++)
{
int j=f[i];
while(j&&s[i]!=s[j]) j=f[j];
f[i+]= s[i]==s[j] ? j+:;
if(i>=&&f[i+])
{
int a=i+-f[i+];
if((i+)%a==) printf("%d %d\n",i+,(i+)/a);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
t++;
if(!n) return ;
scanf("%s",s);
memset(f,,sizeof(f));
printf("Test case #%d\n",t);
getnext();
printf("\n");
}
}
poj 1961 Period的更多相关文章
- KMP POJ 1961 Period
题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...
- POJ 1961 Period( KMP )*
Period Time Limit: 3000MSMemory Limit: 30000K Total Submissions: 12089Accepted: 5656 Description For ...
- POJ 1961 Period(KMP)
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...
- POJ 1961 Period KMP算法next数组的应用
题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...
- (简单) POJ 1961 Period,扩展KMP。
Description For each prefix of a given string S with N characters (each character has an ASCII code ...
- poj 1961 Period 【KMP-next前缀数组的应用】
题目地址:http://poj.org/problem?id=1961 Sample Input 3 aaa 12 aabaabaabaab 0 Sample Output Test case #1 ...
- KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period
首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...
- poj 1961 Period【求前缀的长度,以及其中最小循环节的循环次数】
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 14653 Accepted: 6965 Descripti ...
- poj 1961 Period(KMP训练指南例题)
Period Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 11356 Accepted: 5279 Descripti ...
随机推荐
- pktgen-dpdk 实战
官方手册:http://pktgen-dpdk.readthedocs.io/en/latest/getting_started.html 过程 开机(重启) 把DPDK那一套流程走一遍(环境变量设置 ...
- ejb与javabean的区别总结
EJB的英文全称是企业级的JavaBean 两者是完全不同的 JavaBean是一个组件,而EJB就是一个组建框架 JavaBean面向的是业务逻辑和表示层的显示,通过编写一个JavaBean,可以将 ...
- 如何获取app的activity
(一) 本机安装appium的环境后,在cmd中输入:adb logcat>D:/log.log (二)真题连接电脑或在虚拟机中启动被测试app (三)直接查看d盘的log.log即可从来里面找 ...
- 清除浮动小记,兼容Ie6,7
.clearfix { *zoom:1;} .clearfix:after{clear:both; display:block; height:0; visibility:hidden; line-h ...
- ACM数论之旅2---快速幂,快速求a^b((ノ`Д´)ノ做人就要坚持不懈)
a的b次方怎么求 pow(a, b)是数学头文件math.h里面有的函数 可是它返回值是double类型,数据有精度误差 那就自己写for循环咯 LL pow(LL a, LL b){//a的b次方 ...
- Longest Increasing Subsequence的两种解法
问题描述: 给出一个未排序队列nums,如[10, 9, 2, 5, 3, 7, 101, 18].找出其中最长的增长序列,但不是连续增长序列,如[2, 3, 7, 101]就是对应的最长增长序列LI ...
- mysql索引的优化
MySQL索引的优化 上面都在说使用索引的好处,但过多的使用索引将会造成滥用.因此索引也会有它的缺点:虽然索引大大提高了查询速度,同时却会降低更新表的速度,如对表进行INSERT.UPDATE和DEL ...
- nowcoder 202F-平衡二叉树
题目链接 题目描述 平衡二叉树,顾名思义就是一棵“平衡”的二叉树.在这道题中,“平衡”的定义为,对于树中任意一个节点,都满足左右子树的高度差不超过 d. 空树的高度定义为0,单个节点的高度为1,其他情 ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- BZOJ5120 无限之环(费用流)
方案合法相当于要求接口之间配对,黑白染色一波,考虑网络流.有一个很奇怪的限制是不能旋转直线型水管,考虑非直线型水管有什么特殊性,可以发现其接口都是连续的.那么对于旋转水管,可以看做是把顺/逆时针方向上 ...