地址:http://acm.hust.edu.cn/problem/show/1010

题目:

1010 - The Minimum Length

Time Limit: 1s Memory Limit: 128MB

Submissions: 2502 Solved: 925
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 abcdefgabcdefgabcdefgabcdefg.... 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
思路:kmp+最小循环节
 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int nt[K];
char sa[K],sb[K]; void kmp_next(char *T,int *nt)
{
nt[]=;
for(int i=,j=,len=strlen(T);i<len;i++)
{
while(j&&T[j]!=T[i])j=nt[j-];
if(T[j]==T[i])j++;
nt[i]=j;
}
}
int kmp(char *S,char *T,int *nt)
{
int ans=;
kmp_next(T,nt);
int ls=strlen(S),lt=strlen(T);
for(int i=,j=;i<ls;i++)
{
while(j&&S[i]!=T[j])j=nt[j-];
if(S[i]==T[j])j++;
if(j==lt)
ans++,j=;
}
return ans;
}
int main(void)
{
int t;
while(scanf("%s",sa)==)
{
kmp_next(sa,nt);
int len=strlen(sa);
int ans=len-nt[len-];
printf("%d\n",ans);
}
return ;
}

hust1010 The Minimum Length的更多相关文章

  1. hust--------The Minimum Length (最短循环节)(kmp)

    F - The Minimum Length Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %l ...

  2. (KMP 求循环节)The Minimum Length

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/F The Minimum Length Time Limit: ...

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

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

  4. F - The Minimum Length

    F - The Minimum Length HUST - 1010 #include<cstdio> #include<cstring> #include<iostre ...

  5. HUST 1010 The Minimum Length

    There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I go ...

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

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

  7. The Minimum Length - HUST 1010(求最小循环节)

    题意:有个一字符串A(本身不是循环串),然后经过很多次自增变成AAAAA,然后呢从自增串里面切出来一部分串B,用这个串B求出来A的长度.   分析:其实就是求最小循环节.......串的长度 - 最大 ...

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

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

  9. HUST 1010 The Minimum Length (字符串最小循环节)

    题意 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B.例如有一个字符串A="abcdefg".,复制 ...

随机推荐

  1. 将java项目发布到本地的linux虚拟机上

    1.首先安装虚拟机,这里就不介绍了. 2.然后要我下载了一个WinSCP用于windows和虚拟机之间的文件传输. 首先获得虚拟机的ip: 必须保持连接, 如果断开ip就是这样的 3.传输文件 将jd ...

  2. 为什么Objective-C很难

    转自:http://mobile.51cto.com/hot-322261.htm   2012-03-07 13:43 junwong 开源中国社区 字号:T | T 作为一个Objective-C ...

  3. Arduino开发版学习计划--蜂鸣器

    文章内容参考:http://www.cnblogs.com/xiaowuyi/p/3343757.html 遇到不懂的方法,可以查看Arduino自带的API 就直接点击arduino的IDE里面菜单 ...

  4. angular 4 路由变化的时候实时监测刷新组件

    当路由变化的时候刷新组件 比如说要刷新header组件 在header.ts里 import {Router, NavigationEnd} from "@angular/router&qu ...

  5. 160401、关于cronExpression的介绍

    关于cronExpression的介绍:   每一个字段都有一套可以指定有效值,如 Seconds (秒):可以用数字0-59 表示, Minutes(分)          :可以用数字0-59 表 ...

  6. hibernate中持久化对象的状态

    持久化对象有以下几种状态: 临时对象(Transient): 在使用代理主键的情况下,  OID 通常为 null  不处于 Session 的缓存中 在数据库中没有对应的记录 持久化对象(也叫”托管 ...

  7. 巨蟒python全栈开发-第11阶段 devops-git入门1

    大纲 1.git命令初识 2.git reset与diff 3.git区域总结 4.git 远程仓库 5.git stash 1.git命令初识 2.git reset与diff 3.git区域总结 ...

  8. 每天一個Linux指令- chmod指令

    拷貝來源: 01.http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html 02.http://www.cnblogs.com/peid ...

  9. Django 框架之视图函数(Views)

    http请求中产生的两个核心对象: http请求: HttpRequest对象 http响应: HttpResponse对象 所在位置: django.http HttpRequest 对象的属性和方 ...

  10. 剑指Offer——不用加减乘除做加法

    题目描述: 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. 分析: "^"是不带进位的加法. "&"可以得到所有进位位组 ...