POJ——T 1961 Period
http://poj.org/problem?id=1961
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 18542 | Accepted: 9007 |
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 <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int len,p[N];
char s[N]; inline void Get_next()
{
for(int j=,i=;i<=len;p[i++]=j)
{
for(;s[i]!=s[j+]&&j>;) j=p[j];
if(s[i]==s[j+]) j++;
}
} int main()
{
for(int i=;scanf("%d",&len)&&len;)
{
scanf("%s",s+);
memset(p,,sizeof(p));
Get_next();
printf("Test case #%d\n",++i);
for(int i=;i<=len;i++)
{
int l=i-p[i];
if(i!=l&&i%l==)
printf("%d %d\n",i,i/l);
}
printf("\n");
}
return ;
}
POJ——T 1961 Period的更多相关文章
- KMP POJ 1961 Period
题目传送门 /* 题意:求一个串重复出现(>1)的位置 KMP:这简直和POJ_2406没啥区别 */ /******************************************** ...
- poj 1961 Period
Period http://poj.org/problem?id=1961 Time Limit: 3000MS Memory Limit: 30000K Description Fo ...
- 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 ...
随机推荐
- CF949C Data Center Maintenance(建图+强联通分量)
题意 有 n 个信息中心,第 i 个信息中心要在第 ti 个小时维护,维护期间信息不能被获得. 每个用户的数据都有两份备份,第 i 个用户的数据放在信息中心 c(i,1) 和 c(i,2). 现在要挑 ...
- jquery中$.get()提交和$.post()提交有区别
jquery中$.get()提交和$.post()提交有区别吗? 相同点:都是异步请求的方式来获取服务端的数据: 异同点: 1.请求方式不同:$.get() 方法使用GET方法来进行异步请求的.$.p ...
- 洛谷——P1970 花匠
https://www.luogu.org/problem/show?pid=1970 题目描述 花匠栋栋种了一排花,每株花都有自己的高度.花儿越长越大,也越来越挤.栋栋决定 把这排中的一部分花移走, ...
- php中对象转数组有哪些方法(总结测试)
php中对象转数组有哪些方法(总结测试) 一.总结 一句话总结:json_decode(json_encode($array),true)和array强制转换(或带递归) 1.array方式强制转换对 ...
- SQL 小技能
1. SET STATISTICS TIMEON 附带原文 2.关于索引,是自己可以用Tsql语句建,也可以在设计表的时候选中某一个字段建立索引 一般而言,主键属于聚合索引(字典:A-Z);反 ...
- Network Stack : CookieMonster
CookieMonster The CookieMonster is the class in Chromium which handles in-browser storage, managem ...
- Flex 集合 ArrayCollection 的使用
转:http://keren.iteye.com/blog/380847 转:http://callan.iteye.com/blog/335551 集合是ActionScript 中功能强大的基于索 ...
- python + eclipse + django + postgresql 开发网站(二)
引用与参考 http://www.cnblogs.com/lanxuezaipiao/p/3283932.html python2.7 django1.6 1.新建Django项目
- Windows7下修改pip源
以下列举三种方式的pip源配置: 1. 设置环境变量PIP_CONFIG_FILE指向pip.ini源配置文件,pip.ini文件内容如下: [global] index-url = http://m ...
- 高速改动android系统默认日期方法
高速改动android系统默认日期方法 在android系统的设备上,都有一个默认的開始日期,看过非常多设备,有些设备在没有联网的时候没有同步到系统时间的时候,竟然默认的还是1970年的日期.也见过有 ...