HDU - 1358 - Period (KMP)
Period
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4325 Accepted Submission(s): 2087
one) such that the prefix of S with length i can be written as AK , that is A concatenated K times, for some string A. Of course, we also want to know the period K.
it.
order. Print a blank line after each test case.
3
aaa
12
aabaabaabaab
0
Test case #1
2 2
3 3 Test case #2
2 2
6 2
9 3
12 4
也是一个KMP求周期的题目
与之前类似
不知道为啥next开成全局的就CE了,难道全局的就会和stl里的函数冲突。。
。
AC代码:
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std; int n;
char s[1000005]; int s_next[1000005]; int main() {
int cas = 1;
while(scanf("%d", &n) != EOF) {
if(n == 0) break; memset(s_next, 0, sizeof(s_next));
s_next[0] = -1;
scanf("%s", s);
int i = 0, j = -1;
while(i < n) {
if(j == -1 || s[i] == s[j]) s_next[++ i] = ++ j;
else j = s_next[j];
} printf("Test case #%d\n", cas ++); for(int i = 2; i <= n; i ++) {
int t = i - s_next[i];
if(i % t == 0 && i / t > 1) {
printf("%d %d\n", i, i / t);
}
}
printf("\n");
}
return 0;
}
HDU - 1358 - Period (KMP)的更多相关文章
- HDU 1358 Period(kmp简单解决)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1358 Period (KMP求循环次数)
Problem - 1358 KMP求循环节次数.题意是,给出一个长度为n的字符串,要求求出循环节数大于1的所有前缀.可以直接用KMP的方法判断是否有完整的k个循环节,同时计算出当前前缀的循环节的个数 ...
- hdu 1358:Period(KMP算法,next[]数组的使用)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 1358 Period (kmp判断循环子串)
Period Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- HDU 1358 Period(KMP+最小循环节)题解
思路: 这里只要注意一点,就是失配值和前后缀匹配值的区别,不懂的可以看看这里,这题因为对子串也要判定,所以用前后缀匹配值,其他的按照最小循环节做 代码: #include<iostream> ...
- hdu 1358 Period(kmp求一个串的重复子串)
题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string. ...
- Period(kmp)
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1686 Oulipo (kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...
- POJ 1961 Period(KMP)
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...
随机推荐
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- 洛谷 P1598 垂直柱状图【字符串】
题目描述 写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过72个字符),然后用柱状图输出每个字符在输入文件中出现的次数.严格地按照输出样例来安排你的输出格式. 输入输出格式 输入格式 ...
- 使用Xshell上传下载文件
很多时候我们需要在Windows跟Linux之间,或者Linux跟Linux之间传文件,这里我们讲的是使用Xshell实现文件上传下载. 一.使用rz,sz实现Windows,linux上传下载 1. ...
- Reference resources
CentOS7 (精简操作指令) http://www.centoscn.com/CentOS/help/2016/0429/7147.html
- 算法-基数排序(radix sort)
本文由@呆代待殆原创,转载请注明出处. 简介:这个排序是原来用在卡片排序机上的一个算法,一般用来比较具有多对关键字域的记录,如日期(年月日),通过基数排序我们会依次对年月日这三个关键字进行排序,只要对 ...
- 【强联通分量缩点】【最长路】【spfa】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的讲学计划
10分算法:对于城市网络为一条单向链的数据, 20分算法:对于n<=20的数据,暴力搜出所有的可能路径. 结合以上可以得到30分. 60分算法:分析题意可得使者会带着去的城市也就是这个城市所在强 ...
- 小白的Python之路 day4 不同目录间进行模块调用(绝对路径和相对路径)
一.常用模块调用函数功能解释 1.__file__ 功能:返回自身文件的相对路径 你从pycharm的执行结果可以看出,在pycharm执行atm.py文件时,是从绝对路径下去执行的,而你从cmd下去 ...
- jvm-监控指令-jdump
格式: jmap [option] vmid 作用: 生成堆转储快照. 使用:(注意:需要使用工具打开,分析. 比如: EclipseMemoryAnalyzer)
- oracle: 浅谈sqlnet.ora文件的作用,及SQLNET.AUTHENTICATION_SERVICES设置
关于sqlnet.ora的说明: *****************************************************FROM ORACLE11G DOCS*********** ...
- Linux下使用GDB进行调试
Linux下使用GDB进行调试的常用命令记于此. $ sudo su # g++ -g test.cpp -o test -pthread # gdb test <------- ...