hust1010 The Minimum Length
地址:http://acm.hust.edu.cn/problem/show/1010
题目:
1010 - The Minimum Length
Time Limit: 1s Memory Limit: 128MB
- 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的更多相关文章
- hust--------The Minimum Length (最短循环节)(kmp)
F - The Minimum Length Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- (KMP 求循环节)The Minimum Length
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#problem/F The Minimum Length Time Limit: ...
- KMP + 求最小循环节 --- HUST 1010 - The Minimum Length
The Minimum Length Problem's Link: http://acm.hust.edu.cn/problem/show/1010 Mean: 给你一个字符串,求这个字符串的最小循 ...
- F - The Minimum Length
F - The Minimum Length HUST - 1010 #include<cstdio> #include<cstring> #include<iostre ...
- 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 ...
- HUST 1010 The Minimum Length(KMP,最短循环节点,即i-Next[i])
题意: 有一个字符串A,假设A是“abcdefg”, 由A可以重复组成无线长度的AAAAAAA,即“abcdefgabcdefgabcdefg.....”. 从其中截取一段“abcdefgabcde ...
- The Minimum Length - HUST 1010(求最小循环节)
题意:有个一字符串A(本身不是循环串),然后经过很多次自增变成AAAAA,然后呢从自增串里面切出来一部分串B,用这个串B求出来A的长度. 分析:其实就是求最小循环节.......串的长度 - 最大 ...
- hust 1010 The Minimum Length(循环节)【KMP】
<题目链接> 题目大意: 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B,例如有一个字符串A="a ...
- HUST 1010 The Minimum Length (字符串最小循环节)
题意 有一个字符串A,一次次的重写A,会得到一个新的字符串AAAAAAAA.....,现在将这个字符串从中切去一部分得到一个字符串B.例如有一个字符串A="abcdefg".,复制 ...
随机推荐
- hdu 1813(IDA*)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1813 思路:首先bfs预处理出‘0’到边界点最短距离,然后构造 h() 为所’0‘点逃离迷宫的最少步数 ...
- Spring_day03--Spring配置c3p0连接池和dao使用jdbcTemplate
Spring配置c3p0连接池和dao使用jdbcTemplate 1 spring配置c3p0连接池 第一步 导入jar包 第二步 创建spring配置文件,配置连接池 原始方式 (1)把代码在配置 ...
- 云服务器 ECS Linux 保存用户登录操作命令记录
转载自 : https://help.aliyun.com/knowledge_detail/41210.html 云服务器 ECS Linux 如果要保存用户登录操作记录,则可以通过在 /etc/p ...
- JAVA需要掌握的一些技术
1.你需要精通面向对象分析与设计(OOA/OOD).涉及模式(GOF,J2EEDP)以及综合模式.你应该了解UML,尤其是class,object,interaction以及statediagrams ...
- json、jsonp的定义和区别
一.区别 简单来说,json是一种数据交换格式,jsonp是一种非官方跨域数据交互协议.json描述的是信息的格式,而jsonp是信息传递双方约定的方法.json返回的是一串数据,而 jsonp返回的 ...
- style,currentStyle和getComputedStyle的区别
样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有效. 内部样式(internal Style Sheet):是写在HTML的里面的,内部样式只对 ...
- 基于注解的形式配置Bean
基于注解的方式配置Bean:也就说我们在每个Bean的类名前面注解一下,Spring会自动帮我们扫描Bean放进IOC容器中 I基于注解的方式配置Bean(没有依赖关系的Bean)有两个步骤: 1组件 ...
- hibernate中持久化对象的状态
持久化对象有以下几种状态: 临时对象(Transient): 在使用代理主键的情况下, OID 通常为 null 不处于 Session 的缓存中 在数据库中没有对应的记录 持久化对象(也叫”托管 ...
- 升级PHP版本导致zabbix无法访问解决办法
故障现象:无法打开zabbix首页,提示缺少zabbix.conf配置文件 原因分析:升级yum安装php版本了,升级前卸载了原PHP5.4版本导致 解决办法: 重新安装zabbix yum inst ...
- 解决;R语言使用sqldf库是报错"Failed to connect to database: Error: Access denied for user '..'@'localhost' (using password: NO) Error in !dbPreExists : invalid argument type"
原因:在使用sqldf时,不需要加载RMySQL库 解决方案:在控制台执行释放RMySQL库加载 detach("package:RMySQL", unload=T);