hust--------The Minimum Length (最短循环节)(kmp)
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu
Description
Input
Output
Sample Input
bcabcab
efgabcdefgabcde
Sample Output
3
7 代码:
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
const int maxn=;
int next[maxn];
char str[maxn];
int main()
{
int i,j;
while(scanf("%s",str)!=EOF)
{
j=-;
i=;
next[i]=-;
int len=strlen(str);
while(i<len)
{
if(j==-||str[i]==str[j])
{
i++;
j++;
if(str[i]==str[j])
next[i]=next[j];
else next[i]=j;
}
else j=next[j];
}
//得到最大回缩长度(即最小循环长度;
int cir_len=len-next[len];
printf("%d\n",cir_len);
}
return ;
}
hust--------The Minimum Length (最短循环节)(kmp)的更多相关文章
- hust 1010 The Minimum Length(循环节)【KMP】
<题目链接> 题目大意: 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B,例如有一个字符串A="a ...
- POJ2406-Power Strings-KMP循环节/哈希循环节
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- KMP + 求最小循环节 --- HUST 1010 - The Minimum Length
The Minimum Length Problem's Link: http://acm.hust.edu.cn/problem/show/1010 Mean: 给你一个字符串,求这个字符串的最小循 ...
- HUST 1010 The Minimum Length(KMP,最短循环节点,即i-Next[i])
题意: 有一个字符串A,假设A是“abcdefg”, 由A可以重复组成无线长度的AAAAAAA,即“abcdefgabcdefgabcdefg.....”. 从其中截取一段“abcdefgabcde ...
- KMP解决字符串最小循环节相关问题
经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个 ...
- poj 2406 Power Srings (kmp循环节) (经典)
<题目链接> 题目大意: 给出一个字符串,求其字串在该字符串中循环的最大周期. 解题分析: length=len-Next[len],len为该字符串的最小循环节,如果len%length ...
- (KMP扩展 利用循环节来计算) Cyclic Nacklace -- hdu -- 3746
http://acm.hdu.edu.cn/showproblem.php?pid=3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others ...
- HDU 3746 Cyclic Nacklace(求补齐循环节最小长度 KMP中next数组的使用 好题!!!)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- KMP与循环节相关题目
HDU 3746 Cyclic Nacklace ( KMP求最小循环节 ) len - nextval[len]即为最小循环节长度. #include <cstdio> #include ...
随机推荐
- C# POST与Get数据
引用DLL 普通Get数据和Post数据 public static string Get(string URL) { String ReCode = string.Empty; try { Http ...
- Refresh / Updating a form screen in Oracle D2k Forms 6i
Refresh / Updating a form screen in Oracle D2k Forms 6i ProblemYou want to show number of records pr ...
- FPM的远程利用
看了lijiejie的博客,和乌云的PHPFastCGI的这篇文章,感觉在实际的业务中经常能遇到,所以在此记录下来: 原文:http://www.lijiejie.com/fastcgi-read-f ...
- Spring的起源和背景
上图为Spring框架的组成结构 下面这几张也是的 Spring将大量实际开发中需要重复解决的步骤,抽象成了一个框架. 其中Spring Core Container是Spring框架的核心机制. S ...
- oracle PL/SQL基础编程
PL/SQL(Procedural Language/SQL)是oracle中引入的一种过程化编程语言 PLS-00103:出现符号"declare"在需要下列之一时 符号&quo ...
- 【VB6笔记-02】从Command中获取链接参数
Public Sub GetParameters() Dim Para As String Para = Command$() gstrUserID = GetCommandPara(Para, ) ...
- python_way day13 sqlalchemy
sqlalchemy 一对多 多对多 1.一对多 一.#创建表结构 class Host(Base): #所有的子类都继承这个基类 #创建表结构 __tablename__ = 'hosts' id ...
- Python基础学习笔记(十)日期Calendar和时间Timer
参考资料: 1. <Python基础教程> 2. http://www.runoob.com/python/python-date-time.html 3. http://www.liao ...
- HTML笔记(一)
HTML注释格式如下: <!-- 这里是注释 --> HTML中的标题(heading)通过h1~h6来定义. 文本格式化标签: 标签 描述 <b> 定义粗体文本. <b ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...