【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 ...
随机推荐
- 在ASP.NET MVC中对手机号码的验证
在ASP.NET MVC中,可以使用RegularExpression特性来验证手机号码. public class Customer { [Required(ErrorMessage = " ...
- HDOJ1020 Encoding
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- HDU 3555 Bomb(数位DP)
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- Little shop of flowers - SGU 104 (DP)
题目大意:把 M 朵花插入 N 个花瓶中,每个花插入不同的花瓶都有一个价值A[Mi][Nj],要使所有的花都插入花瓶,求出来最大的总价值(花瓶为空时价值是0). 分析:dp[i][j]表示前i朵花插入 ...
- ajaxPro用法
一.AjaxPro的使用 1.在项目中添加引用,浏览找到AjaxPro.2.dll文件 2.在Web.config中的system.web里面写入以下代码 </configuration> ...
- 分享一个很好看的WPF界面
今天在http://www.iopenworks.com/Products/ProductDetails/Introduction?proID=386 上面看到的,先mark下来...... 地址:h ...
- Qt 发送 https 请求
1.环境 ubuntu 12.04 Qt库版本 4.8.1(安装包是Nokia时期的sdk,现在已经不好找了) 2.网上一查都说 Qt 默认不支持Openssl,心想那https也肯定用不了啊,然后屁 ...
- 改变Android按钮背景颜色的高效方法
本文将介绍一种有效改变Android按钮颜色的方法. 按钮可以在状态改变时改变其颜色(例如按下,禁用,高亮显示).但是,这需要一一说明每个状态.这篇文章将提供你一个根据状态变化轻松改变按钮颜色的方法. ...
- gdb - 列出所有函数调用
How can we list all the functions being called in an application For any realistically sized applica ...
- 使用org.apache.jasper.JspC编译jsp文件--转载
JspC可以通过jspc.setArgs(args);设置所需参数,和使用指令进行编译相同, 使用指令编译范例: java -cp jasper.jar;servlet-api.jar;Fcatali ...