地址: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. LoadRunner检查点实战之运行查看器

    一.为什么要使用检查点 为什么要使用检查点,那就要说明一下LR如何判断脚本是否执行成功.LR判断脚本是否执行成功是根据服务器返回的状态来确定的,如果服务器返回的HTTP状态为 200 OK ,那么Vu ...

  2. hdu 4240在(最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...

  3. 剑指 offer set 13 把数组排成最小的数

    总结 1. 给定 3, 32, 321 将他们组合成最小的数, 比如 321323 2. 3    ->   333 32   ->   322 321 ->   321 然后再排序

  4. ios8推送问题

    博文转载至  http://blog.csdn.net/cerastes/article/details/39546625 ios8push推送通知适配 ios8推送问题 registerForRem ...

  5. linux安装yaf(ubuntu教程)

    $PHP_BIN/phpize 这个是什么 其实这个是一个扩展 apt-get install php5-dev 这样电脑会帮你自己配置了,很简单的下面我们就下载扩展包了http://pecl.php ...

  6. 一直深深困扰我的问题——hadoop 重启集群后,之前运行的job运行状态都丢失了

    努力之后总是存在回报的,我花了三天时间终于找到了问题所在: 配置文件yarn-site.xml: <property>        <name>yarn.resourcema ...

  7. UNION WHERE

    w条件语句的作用域. SELECT * FROM ( SELECT asin, LOWER(country) AS country FROM grab_amzreviews_asins UNION D ...

  8. php格式化输出数组

    写网页的时候经常需要在页面中打印数组,但格式特别难看,看看一个html神器吧<pre>标签,能非常标准的显示数组格式 使用的时候只需要这样打印你的数组就OK了,太好用了,神器! echo ...

  9. 如何在 windows 配置 libtorch c++ 前端库?

    如何在 windows 配置 libtorch c++ 前端库? 下载 pytorch 已经编译好的库: 此库不带 gpu,主要方便演示.支持 win7 win10 系统. 下载地址:https:// ...

  10. 【numpy】

    ndarray在某个维度上堆叠,np.stack() np.hstack() np.vstack() https://blog.csdn.net/csdn15698845876/article/det ...