【POJ2406】【KMP】Power Strings
Description
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
Source
/*
唐代李白
《三五七言 / 秋风词》 秋风清,秋月明,
落叶聚还散,寒鸦栖复惊。
相思相见知何日?此时此夜难为情!
入我相思门,知我相思苦。
长相思兮长相忆,短相思兮无穷极。
早知如此绊人心,何如当初莫相识。
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <iomanip>
#include <string>
#include <cmath>
#include <queue>
#include <assert.h>
#include <map>
#include <ctime>
#include <cstdlib>
#include <stack>
#define LOCAL
const int MAXN = + ;
const int INF = ;
const int SIZE = ;
const int MAXM = + ;
const int maxnode = 0x7fffffff + ;
using namespace std;
int l1, l2;
char a[MAXN], b[MAXN];
int next[];//不用开太大了..
void getNext(){
//初始化next数组
next[] = ;
int j = ;
for (int i = ; i <= l1; i++){
while (j > && a[j + ] != a[i]) j = next[j];
if (a[j + ] == a[i]) j++;
next[i] = j;
}
return;
}
int kmp(){
int j = , cnt = ;
for (int i = ; i <= l2; i++){
while (j > && a[j + ] != b[i]) j = next[j];
if (a[j + ] == b[i]) j++;
if (j == l1){
cnt++;
j = next[j];//回到上一个匹配点
}
}
return cnt;
} void init(){
scanf("%s", a + );
scanf("%s", b + );
l1 = strlen(a + );
l2 = strlen(b + );
} int main(){
int T; while (scanf("%s", a + )){
if (a[] == '.') break;
l1 = strlen(a + );
getNext();
if (l1%(l1 - next[l1]) == ) printf("%d\n", l1/(l1 - next[l1]));
else printf("1\n");
}
return ;
}
【POJ2406】【KMP】Power Strings的更多相关文章
- 【POJ2406】 Power Strings (KMP)
Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...
- 【poj 2406】Power Strings 后缀数组DC3模板 【连续重复子串】
Power Strings 题意 给出一个字符串s,求s最多由几个相同的字符串重复而成(最小循环节的重复次数) 思路 之前学习KMP的时候做过. 我的思路是:枚举字符串的长度,对于当前长度k,判断\( ...
- poj 2406 Power Strings【最小循环节】
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36926 Accepted: 15254 D ...
- poj 2406 Power Strings【字符串+最小循环节的个数】
Po ...
- HDU 6034 Balala Power!【排序/进制思维】
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java ...
- 【KMP】【最小表示法】NCPC 2014 H clock pictures
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...
- 【动态规划】【KMP】HDU 5763 Another Meaning
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...
- 【一天一道LeetCode】#342. Power of Four
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
- 21.翻译系列:Entity Framework 6 Power Tools【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/entity-framework-power-tools.aspx 大家好,这里就是EF ...
随机推荐
- json串的使用
一:在C#中使用json字符串 从这里下载:http://www.newtonsoft.com/products/json/ 安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2. ...
- HDU-2126 Buy the souvenirs
数组01背包. http://acm.hdu.edu.cn/showproblem.php?pid=2126 http://blog.csdn.net/crazy_ac/article/details ...
- bzoj 1096 [ZJOI2007]仓库建设(关于斜率优化问题的总结)
1096: [ZJOI2007]仓库建设 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3234 Solved: 1388[Submit][Stat ...
- flexpaper 与js 交互
flash 代码//写到要响应的方法体中import flash.external.ExternalInterface;ExternalInterface.call("alert" ...
- hdoj 4324 Triangle LOVE【拓扑排序判断是否存在环】
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- zoj 2100 Seeding
Seeding Time Limit: 2 Seconds Memory Limit: 65536 KB It is spring time and farmers have to plan ...
- 实现网页页面跳转的几种方法大全(meta标签、js实现、php实现)
1.meta标签实现 只需在head里加上下面这一句就行了,在当前页面停留0.1秒后跳转到目标页面 代码如下 复制代码 1 <meta http-equiv="refresh&quo ...
- 使用Python扫描端口情况
#!/usr/bin/python# -*- coding:utf8 -*-# Python: 2.7.8# Platform: Windows# Authro: ...
- C# 打开PPT文件另存为PPTX
/// <summary> /// rename PPT /// </summary> private static void renamePPT() { //add refe ...
- Python基础 1----Python语言基础和Python环境准备与安装
引导语: 人们学习Python是因为他们爱这门语言,因为他们追寻美,如果我雇用一个Python程序员,那么他们的技术将非常的棒 1 Python是一门跨平台的语言,是一种面向对象的动态编程语言 发布时 ...