FZU-1901-Period 2(KMP)
链接:
https://vjudge.net/problem/FZU-1901
题意:
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 prefix is a “period” of S. We want to all the periodic prefixs.
思路:
求可能的循环节长度.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e6+10;
const int MOD = 1e4+7;
char a[MAXN];
int Next[MAXN], Res[MAXN];
int n;
void GetNext(char *s)
{
int len = strlen(s);
int j = 0, k = -1;
Next[0] = -1;
while (j < len)
{
if (k == -1 || s[j] == s[k])
{
++j;
++k;
Next[j] = k;
}
else
k = Next[k];
}
}
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while (t--)
{
scanf("%s", a);
int len = strlen(a);
GetNext(a);
int ans = 0;
int p = len;
while (p > 0)
{
Res[++ans] = len-Next[p];
p = Next[p];
}
printf("Case #%d: %d\n", ++cnt, ans);
printf("%d", Res[1]);
for (int i = 2;i <= ans;i++)
printf(" %d", Res[i]);
puts("");
}
return 0;
}
FZU-1901-Period 2(KMP)的更多相关文章
- 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 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). 题解:这个题是真的坑,一开始怎么都觉得自己不可能错,然后看 ...
- Period II FZU - 1901(拓展kmp)
拓展kmp板题 emm...我比较懒 最后一个字母进了vector两个1 不想改了...就加了个去重... 哈哈 #include <iostream> #include <cst ...
- FZU 1901 Period II(KMP中的next)题解
题意:给你一串字符串,问你前后缀相同情况有几种,并输出后缀位置(?这里一直没看懂length是什么,但是这样理解答案也对,然后还要加上本身长度) 思路:这里好好讲讲next的用法.我们都知道next代 ...
- (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 ...
- Period II - FZU 1901(KMP->next)
题目大意:给你一个字符串 S ,N = |S|,如果存在一个 P (1<=P<=N),并且满足 s[i] = s[P+i] (i = {0...N-P-1} ),求出来所有的 P 然后输出 ...
随机推荐
- WijmoJS V2019.0 Update2发布:再度增强 React 和 Vue 框架的组件功能
前端开发工具包 WijmoJS 在2019年的第二个主要版本 V2019.0 Update2 已经发布,本次发布涵盖了React 和 Vue 框架下 WijmoJS 前端组件的功能增强,并加入更为易用 ...
- stalstack
Saltstack 是干什么的 saltstack 是一个开源异构平台基础设置管理工具 Saltstack 能干什么 如果是一个管理成千上百服务器的管理员,你会遇到场景 需要在每台服务器上面部署age ...
- T100弹出是否确认窗体方式
例如: IF NOT cl_ask_confirm('aim-00108') THEN CALL s_transaction_end(') CALL cl_err_collect_show() RET ...
- IDEA将项目打包为指定class文件的jar
转自:https://blog.csdn.net/makang456/article/details/86699375 [背景] 公司最近要和某大公司合作,将本公司的产品提供给其它公司单独部署 ...
- es6 getter setter
https://stackoverflow.com/questions/34517538/setting-an-es6-class-getter-to-enumerable 1. 我要 getter ...
- Spring MVC(一)Spring MVC的原理
1.Spring MVC的目的 构建像Spring框架那样灵活和松耦合的Web应用程序. 2.Spring MVC中如何处理Request? 每当用户在Web浏览器中点击链接或者提交表单时,Reque ...
- 管家婆crm9.2 sp2升级问题求助及解决方案
升级过程中发生如下问题: 弹出对话框1:升级完成,但是有错误产生. 弹出对话框2:升级数据库发生错误:An attempt was made to load an assembly from a ne ...
- 服务端相关知识学习(三)Zookeeper的配置
前面两篇文章介绍了Zookeeper是什么和可以干什么,那么接下来我们就实际的接触一下Zookeeper这个东西,看看具体如何使用,有个大体的感受,后面再描述某些地方的时候也能在大脑中有具体的印象.本 ...
- 使用WSAIoctl获取AcceptEx,Connectex,Getacceptexsockaddrs函数指针
运行WinNT和Win2000的系统上,这些APIs在Microsoft提供的DLL(mswsock.dll)里实现,可以通过链接mswsock.lib或者通过WSAioctl的SIO_GET_EXT ...
- python爬虫redis-ip代理池搭建几十万的ip数据--可以使用
from bs4 import BeautifulSoupimport requests,os,sys,time,random,redisfrom lxml import etreeconn = re ...