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 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.
InputMultiply 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.
OutputFor each line, output an integer, as described above.Sample Input
bcabcab
efgabcdefgabcde
Sample Output
3
7 kmp求最小循环节。 代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> char str[];
int Next[],len,k;
void findNext() {
int j = -,i = ;
Next[] = -;
while(i < len) {
if(j == - || str[i] == str[j]) {
Next[++ i] = ++ j;
}
else j = Next[j];
}
}
int main() {
while(~scanf("%s",str)) {
len = strlen(str);
findNext();///先确立Next数组 printf("%d\n",len - Next[len]);
}
}
HUST 1010 The Minimum Length的更多相关文章
- 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 ...
- hust 1010 The Minimum Length(循环节)【KMP】
<题目链接> 题目大意: 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B,例如有一个字符串A="a ...
- HUST 1010 The Minimum Length (字符串最小循环节)
题意 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B.例如有一个字符串A="abcdefg".,复制 ...
- HUST - 1010 The Minimum Length(最小循环节)
1.赤裸裸的最小循环节 2. 3. #include<iostream> #include<stdio.h> #include<string.h> using na ...
- hust1010 The Minimum Length
地址:http://acm.hust.edu.cn/problem/show/1010 题目: 1010 - The Minimum Length Time Limit: 1s Memory Limi ...
- (KMP 求循环节)The Minimum Length
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/F The Minimum Length Time Limit: ...
- F - The Minimum Length
F - The Minimum Length HUST - 1010 #include<cstdio> #include<cstring> #include<iostre ...
- hust--------The Minimum Length (最短循环节)(kmp)
F - The Minimum Length Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
随机推荐
- LeetCode:为运算表达式设置优先级【241】
LeetCode:为运算表达式设置优先级[241] 题目描述 给定一个含有数字和运算符的字符串,为表达式添加括号,改变其运算优先级以求出不同的结果.你需要给出所有可能的组合的结果.有效的运算符号包含 ...
- 面向过程编程实例------grep-rl 'root 路径
#应用:grep -rl 'root' /etc import os def deco(func): def wrapper(*args): g=func(*args) next(g) return ...
- HNOI2019梦游记
\(Day_0\) 十点半开始睡觉,开始了八个小时的不眠之夜,整晚都没睡着,这状态明天肯定挂了 \(Day_1\) 开局一条鱼,计算几何只会\(20\) 还是\(T2\)的\(20\)纯暴力好打,\( ...
- leetcode刷题1:两数之和two_sum
题目:(难度:Easy) 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, ...
- 常见Web安全漏洞
1.web安全常见攻击手段 xss sql注入 防盗链 csrf 上传漏洞 2. 信息加密与漏洞扫描 对称加密 非对称加密 3. 互联网API接口安全设计 4. 网站安全漏洞扫描与 ...
- cuffdiff problem--Performed 0 isoform-level transcription difference tests
如何解决cuffdiff运行结果中表达量为0的情况? cuffdiff -o cdiffout -b ref.fasta -u -p 15 --library-type fr-firststrand ...
- elasticsearch中filter执行原理深度剖析(bitset机制与caching机制)
(1)在倒排索引中查找搜索串,获取document list date来举例 word doc1 doc2 doc3 2017-01-01 * *2017-02-02 * *2017-03-03 ...
- JavaWeb -- Jsp 和 JavaBean
JSP技术提供了三个关于JavaBean组件的动作元素,即JSP标签,它们分别为: <jsp:useBean>标签:用于在JSP页面中查找或实例化一个JavaBean组件. <jsp ...
- QT 中一些数学计算函数
QT的一些範例中有出現 qmax, qmin 等 math函式的身影,但我在官方文件中卻找不到與 math函式相關的說明,所以我就把函式的source裡面提供的方法整理條列,並且看看還有哪些 math ...
- 使用log4j2打印Log,log4j不能打印日志信息,log4j2不能打印日志信息,log4j和logj2,idea控制台信息乱码(文末)
说来惭愧,今天就写了个"hello world",了解了一下log4j的日志. 本来是想在控制台打印个log信息,也是遇到坎坷重重,开始也没去了解log4j就来使用,log4j配置 ...