F - The Minimum Length

Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu

Submit Status

Description

There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then, give you the string B, can you tell me the length of the shortest possible string A. For example, A="abcdefg". I got abcd efgabcdefgabcdefgabcdefg.... Then I cut the red part: efgabcdefgabcde as string B. From B, you should find out the shortest A.

Input

Multiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000,000.

Output

For each line, output an integer, as described above.

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)的更多相关文章

  1. hust 1010 The Minimum Length(循环节)【KMP】

    <题目链接> 题目大意: 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B,例如有一个字符串A="a ...

  2. POJ2406-Power Strings-KMP循环节/哈希循环节

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  3. KMP + 求最小循环节 --- HUST 1010 - The Minimum Length

    The Minimum Length Problem's Link: http://acm.hust.edu.cn/problem/show/1010 Mean: 给你一个字符串,求这个字符串的最小循 ...

  4. HUST 1010 The Minimum Length(KMP,最短循环节点,即i-Next[i])

    题意: 有一个字符串A,假设A是“abcdefg”,  由A可以重复组成无线长度的AAAAAAA,即“abcdefgabcdefgabcdefg.....”. 从其中截取一段“abcdefgabcde ...

  5. KMP解决字符串最小循环节相关问题

    经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个 ...

  6. poj 2406 Power Srings (kmp循环节) (经典)

    <题目链接> 题目大意: 给出一个字符串,求其字串在该字符串中循环的最大周期. 解题分析: length=len-Next[len],len为该字符串的最小循环节,如果len%length ...

  7. (KMP扩展 利用循环节来计算) Cyclic Nacklace -- hdu -- 3746

    http://acm.hdu.edu.cn/showproblem.php?pid=3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others ...

  8. HDU 3746 Cyclic Nacklace(求补齐循环节最小长度 KMP中next数组的使用 好题!!!)

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. KMP与循环节相关题目

    HDU 3746 Cyclic Nacklace ( KMP求最小循环节 ) len - nextval[len]即为最小循环节长度. #include <cstdio> #include ...

随机推荐

  1. tophat cufflinks cuffcompare cuffmerge 的使用

    Cole Trapnell said: there are three strategies: 1) merge bams and assemble in a single run of Cuffli ...

  2. freebsd镜像作用和vmware服务开启

    第一个是可以引导的光盘,只能引导系统,通常用于网络安装.基本没用.第二个是系统光盘的第一张.用这张就可以安装一个基本的系统.其他的软件,在系统安装完之后安装.第三个是系统盘的DVD版本.包括的软件比上 ...

  3. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  4. S3C2440的GPIO编程

    一.初步认识S3C2440A [S3C2440A简介] S3C2440A是三星公司推出的基于ARM920t内核的32/16位RISC微处理器.主要用于手持设备和中高端电子产品中.它内部集成16k数据c ...

  5. [转载] C++ 程序员快过来围观:非常实用全面的 C++ 资源

    原文: http://codecloud.net/c-plus-plus-resource-2983.html 绝对是c++开发者的福音啊, 必须推荐. 这次的资源涉及到了标准库.Web应用框架.人工 ...

  6. C/C++中static关键字作用总结

    来来来,来看这篇文章: http://www.cnblogs.com/biyeymyhjob/archive/2012/07/19/2598815.html 总结一下: 1.先来介绍它的第一条也是最重 ...

  7. 关于level DB的相关资料

    可以参考: http://blog.csdn.net/houzengjiang/article/details/7718548 http://www.cnblogs.com/haippy/archiv ...

  8. SVN标准目录结构

    Trunk 这是SVN目录的主分支,表示日常开发中的项目,任何时候Trunk里包含的都是最新的开发代码. 这里的代码将会工作到你的下一个主要发布版本. Trunk应该只被用来开发将会成为你的下一个重要 ...

  9. linux 多线程信号处理总结

    linux 多线程信号总结(一) 1. 在多线程环境下,产生的信号是传递给整个进程的,一般而言,所有线程都有机会收到这个信号,进程在收到信号的的线程上下文执行信号处理函数,具体是哪个线程执行的难以获知 ...

  10. Android广播BroadcastReceiver 二

    BroadcastReceiver: 在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.而BroadcastReceiver是对发送出来的 Broadcast进行过滤 ...