(KMP Next的运用) Period II -- fzu -- 1901
http://acm.fzu.edu.cn/problem.php?pid=1901
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/Q
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
S[i]=S[i+P] for i in [0..SIZE(S)-p-1],
then the prefix is a “period” of S. We want to all the periodic prefixs.
Input
The first line contains an integer T representing the number of cases. Then following T cases.
Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.
Output
Sample Input
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm> using namespace std; const int maxn = ; char s[maxn];
int Next[maxn], ans[maxn]; void FindNext(char s[])
{
int slen = strlen(s), i=, j=-;
Next[] = -; while(i<slen)
{
if(j==- || s[i]==s[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{
int t, iCase=;
scanf("%d", &t);
while(t--)
{
scanf("%s", s); int len = strlen(s); FindNext(s); int cnt = , k=len; while(Next[k]!=)
{
ans[cnt++] = len-Next[k]; /// 第 cnt 个子串结束的下标, 表示自己觉得很神奇
k = Next[k];
} printf("Case #%d: %d\n", iCase++, cnt+);
for(int i=; i<cnt; i++)
printf("%d ", ans[i]);
printf("%d\n", len);
}
return ;
}
(KMP Next的运用) Period II -- fzu -- 1901的更多相关文章
- Period II FZU - 1901(拓展kmp)
拓展kmp板题 emm...我比较懒 最后一个字母进了vector两个1 不想改了...就加了个去重... 哈哈 #include <iostream> #include <cst ...
- Period II - FZU 1901(KMP->next)
题目大意:给你一个字符串 S ,N = |S|,如果存在一个 P (1<=P<=N),并且满足 s[i] = s[P+i] (i = {0...N-P-1} ),求出来所有的 P 然后输出 ...
- Fzu Problem 1901 Period II (kmp)
题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...
- FZU - 1901 Period II (kmp)
传送门:FZU - 1901 题意:给你个字符串,让你求有多少个p可以使S[i]==S[i+P] (0<=i<len-p-1). 题解:这个题是真的坑,一开始怎么都觉得自己不可能错,然后看 ...
- FZU1901 Period II —— KMP next数组
题目链接:https://vjudge.net/problem/FZU-1901 Problem 1901 Period II Accept: 575 Submit: 1495Time Lim ...
- FZU - 1901 Period II(kmp所有循环节)
Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SI ...
- FZU 1901 Period II(KMP循环节+公共前后缀)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要 ...
- [FZU 1901]Period II KMP
For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SIZE(S)-p-1], then the ...
- FZU 1901 Period II(KMP中的next)题解
题意:给你一串字符串,问你前后缀相同情况有几种,并输出后缀位置(?这里一直没看懂length是什么,但是这样理解答案也对,然后还要加上本身长度) 思路:这里好好讲讲next的用法.我们都知道next代 ...
随机推荐
- 由于C++类库版本不同导致的OpenCV编译链接错误
太长不看版:GCC4和GCC5使用的C++标准库下,string的名字不一样,导致链接错误. 之前在Ubuntu下使用OpenCV的时候一切正常.后来再次编译的时候,连接器提示有些库函数找不到: ma ...
- MapReduce超时原因(Time out after 300 secs)
目前碰到过三种原因导致 Time out after 300 secs. 1. 死循环 这是最常见的原因.显式的死循环很容易定位,隐式的死循环就比较麻烦了,比如正则表达式.曾经用一个网上抄来的邮箱正则 ...
- fiddler 发送get请求
点击Composer 点击执行(Execute) \ 这里演示的是带cookie
- java链接FTP实现上传和下载
FtpUtil.java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStr ...
- EasyUI 列表展示及基本格式
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- testlink问题--linux环境下
搭建testlink 时出现问题,相关解决办法: 1.Maximum Session Idle Time before Timeout 修改php.ini文件,修改成session.gc_maxlif ...
- 89. Gray Code (Bit)
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- Jiu Yuan Wants to Eat(树链剖分+线段树延迟标记)
Jiu Yuan Wants to Eat https://nanti.jisuanke.com/t/31714 You ye Jiu yuan is the daughter of the Grea ...
- TIME_WAIT状态的作用
TIME_WAIT状态: 主动关闭的那端最后经历的状态,一般为2MSL秒(1~4分钟). 两个原因: 保证当最后一个ack丢失后,能收到对端重传的fin包. 保证ack包消失,不会影响下一个连接. 关 ...
- Golang之写一个聊天室
. 海量用户在线聊天系统 . 点对点聊天 . 用户登录&注册 一.服务端开发 . 用户管理 用户id:数字 用户密码:字母数字组合 用户昵称:用来显示 用户性别:字符串 用户头像:url 用户 ...