HUST1010-The Minimum Length
来源:互联网 发布:类似淘宝千里眼的插件 编辑:程序博客网 时间:2024/06/03 15:28
The Minimum Length
时间限制:1秒 内存限制:128兆
2266 次提交 837 次通过
- 题目描述
- 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.
- 输入
- 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.
- 输出
- For each line, output an integer, as described above.
- 样例输入
bcabcabefgabcdefgabcde
- 样例输出
37
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>using namespace std;#define N 1000005char str[N];int f[N];int main(){ while(~scanf("%s",str)) { int len=strlen(str); f[0]=-1; for(int i=0;i<len;i++) { int k=f[i]; while(k>=0&&str[i]!=str[k]) k=f[k]; f[i+1]=k+1; } printf("%d\n",len-f[len]); } return 0;}
0 0
- hust1010 The Minimum Length
- HUST1010-The Minimum Length
- HUST1010 The Minimum Length
- HUST1010——The Minimum Length(KMP)
- F - The Minimum Length HUST1010( kmp计算最小循环节)
- The Minimum Length 【kmp】
- The Minimum Length KMP
- The Minimum Length
- hust 1010 The Minimum Length
- hust 1010 The Minimum Length
- HUST - 1010 The Minimum Length
- hust 1010 The Minimum Length
- HUST 1010The Minimum Length
- HUST 1010 The Minimum Length
- HUST 1010 The Minimum Length
- The Minimum Length (HUST_1010) KMP
- HUST 1010 The Minimum Length
- HUST 1010 The Minimum Length
- listview 的分页加载
- 郑大第九届校赛-热身赛-zzulioj-1809-make pair
- 八.删除文件
- Python实现二叉树及其4种遍历
- libevent学习之helloworld
- HUST1010-The Minimum Length
- Activity——showDialog()、onPrepareDialog()和onCreateDialog()的关系
- Eclipse启动tomcat错误
- 第二十六条:优先考虑泛型
- 九.远程仓库
- 计数排序算法实现
- 数据库连接的步骤
- 十.添加远程库
- 微信公众号开发---微信接口素材管理