Period II
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
4
ooo
acmacmacmacmacma
fzufzufzuf
stostootssto
Sample Output
Case #1: 3
1 2 3
Case #2: 6
3 6 9 12 15 16
Case #3: 4
3 6 9 10
Case #4: 2
9 12
题意:求所有的循环节
思路:循环ans=ne[ans],len-ans
#include <iostream>
#include<string.h>
using namespace std;
const int maxn = 1e6+;
char a[maxn];
int ne[maxn],sum[maxn];
int main()
{
int t;
int num=;
scanf("%d",&t);
while(t--)
{
memset(ne,,sizeof(ne));
scanf("%s",a+);
int len=strlen(a+);
for(int i=,j=;i<=len;i++)
{
while(j&&a[i]!=a[j+]) j=ne[j];
if(a[i]==a[j+]) j++;
ne[i]=j;
}
int ans=len,cnt=;
while(ans)
{
ans=ne[ans];
sum[++cnt]=len-ans;
}
printf("Case #%d: %d\n",++num,cnt);
for(int i=;i<=cnt-;i++)
printf("%d ",sum[i]);
printf("%d\n",sum[cnt]);
}
return ;
}
Period II的更多相关文章
- (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=703 ...
- FZU1901 Period II —— KMP next数组
题目链接:https://vjudge.net/problem/FZU-1901 Problem 1901 Period II Accept: 575 Submit: 1495Time Lim ...
- Fzu Problem 1901 Period II (kmp)
题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...
- 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
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 ...
- Q - Period II
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 ...
- 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 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中的next)题解
题意:给你一串字符串,问你前后缀相同情况有几种,并输出后缀位置(?这里一直没看懂length是什么,但是这样理解答案也对,然后还要加上本身长度) 思路:这里好好讲讲next的用法.我们都知道next代 ...
随机推荐
- 【leetcode】Global and Local Inversions
题目如下: We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (g ...
- 30. ClustrixDB 分布式架构/Rebalancer
Rebalancer是一个自动化系统,用于维护集群中数据的健康分布.通过修改数据的分布和位置来响应“不健康”集群是Rebalancer的工作.Rebalancer是一个在线进程,它影响对集群的更改,对 ...
- 8. ClustrixDB 监控
一. 列出集群中当前会话 sql> select * from system.sessions\G 二. 显示CPU利用率.磁盘读/写利用率和缓冲区缓存失误率 MySQL [system]> ...
- docker开启远程tcp监听端口
linux 测试成功 cat > /etc/systemd/system/docker.service.d/tcp.conf <<EOF [Service] ExecStart= E ...
- jquery eq()选择器 语法
jquery eq()选择器 语法 作用::eq() 选择器选取带有指定 index 值的元素.index 值从 0 开始,所有第一个元素的 index 值是 0(不是 1).经常与其他元素/选择器一 ...
- FZU 2203 单纵大法好 (二分 && 贪心)
题意 : 老S最近喜欢上某个搜集战舰的游戏,这个游戏中很重要的一个内容是能编排自己的战舰,通过出击完成任务来获取资源或新的战舰.大家都说老S是一个“直男”,所以他喜欢把战舰排成一条直线.目前老S正准备 ...
- 阿里云ECS服务器socket无法连接的问题
把自己的项目部署到阿里云ecs服务器之后,只有127.0.0.1才能连接到服务器端,检查了阿里云安全组规则,以及socket绑定的地址无误后,发现没有开启服务器防火墙的对应端口. firewall-c ...
- NBU5240备份系统还原数据库---Windows版
NBU5240是一个基于系统文件和多种数据库备份的灾备系统,灵活性比较高.下面具体记录如何利用该系统的备份文件进行数据库还原.(基于业务场景) 公司某业务部门突然发现前台系统数据有异常,已经是几天前的 ...
- 大哥带的MSsql注入(SQL Server)--预习
①判断数据库类型and exists (select * from sysobjects)--返回正常为mssql(也名sql server)and exists (select count(*) f ...
- wannalfy 挑战赛7 E 珂朵莉与GCD (离线+线段树/树状数组)
链接:https://www.nowcoder.com/acm/contest/56/E 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 716800K,其他语言1433600K 6 ...