hdu 3746 Cyclic Nacklace
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746
思路:KMP中Next数组的应用,求出最小的循环节,题目的意思是只能在字符串的后面上添加新的字符凑成两个循环节
用Next数组来求最小循环节的方法见这:http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html
#include<string.h>
#include<stdio.h>
#include<iostream>
#define N 1000005 using namespace std; int Next[N],tlen;
char T[N]; void getNext()
{
int j, k;
j = ; k = -; Next[] = -;
while(j < tlen)
{
if(k == - || T[j] == T[k])
Next[++j] = ++k;
else
k = Next[k];
}
} int main()
{
int cas,min;
scanf("%d",&cas);
while(cas--)
{
scanf("%s",T);
tlen=strlen(T);
getNext();
min=tlen-Next[tlen];
if(min==tlen)
printf("%d\n",tlen);
else if(tlen%min==)
printf("0\n");
else
printf("%d\n",min-tlen%min);
}
return ;
}
hdu 3746 Cyclic Nacklace的更多相关文章
- 模板题 + KMP + 求最小循环节 --- HDU 3746 Cyclic Nacklace
Cyclic Nacklace Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3746 Mean: 给你一个字符串,让你在后面加尽 ...
- HDU 3746 Cyclic Nacklace (用kmp求循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3746 Cyclic Nacklace(求补齐循环节最小长度 KMP中next数组的使用 好题!!!)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3746 Cyclic Nacklace(kmp next数组运用)
Cyclic Nacklace Problem Description CC always becomes very depressed at the end of this month, he ha ...
- hdu 3746 Cyclic Nacklace KMP循环节
Cyclic Nacklace 题意:给一个长度为Len( 3 <= Len <= 100000 )的英文串,问你在字符串后面最少添加几个字符可以使得添加后的串为周期串? Sample I ...
- HDU 3746 Cyclic Nacklace (KMP找循环节)
题目链接:HDU 3746 Sample Input 3 aaa abca abcde Sample Output 0 2 5 Author possessor WC Source HDU 3rd & ...
- HDU 3746 - Cyclic Nacklace & HDU 1358 - Period - [KMP求最小循环节]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 3746 Cyclic Nacklace KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...
- hdu 3746 Cyclic Nacklace(kmp最小循环节)
Problem Description CC always becomes very depressed at the end of this month, he has checked his cr ...
随机推荐
- mysql5.7.10 的源码安装
mysql 5.7.10的源码安装:http://fyduan.blog.51cto.com/4234935/1729873cmake . -DCMAKE_INSTALL_PREFIX=/usr/lo ...
- 大图居中,以1920px为例
<div style="overflow: hidden; position: relative;"> <img src="img.jpg" ...
- Azure SQL Data Warehouse
Azure SQL Data Warehouse & AWS Redshift Amazon Redshift Amazon Redshift 是一种快速.完全托管的 PB 级数据仓库,可方便 ...
- MFC 文件遍历
对文件的操作MFC提供了CFileFind 类,运用此类,我们可以轻松的多文件进行操作 假设我们删除当前目录下所有jpg格式的图片: CFileFind finder; CFile fp; bool ...
- 收集的在线图片压缩(jpg/png)
http://www.yasuotu.com/ http://www.jpegmini.com/ http://www.tumiaoya.com/ https://tinypng.com/(推荐) h ...
- hosts manager——hosts配置管理工具
引言 做web开发相关的经常会用到hosts修改的功能,各个平台好像都有hosts 配置GUI(据我所知windows有.MAC OX也有),但是命令行配置hosts的好像还没有,命令行配置的话有几个 ...
- wpf converter converterparameter 绑定多参数
1. converterparameter不是依赖属性,所以不能用binding. 2. 可以把converter 的接口 IValueConverter改为 IMultiValueConverter ...
- CFBundleVersion与CFBundleShortVersionString,上架注意事项
CFBundleVersion,标识(发布或未发布)的内部版本号.这是一个单调增加的字符串,包括一个或多个时期分隔的整数. CFBundleShortVersionString 标识应用程序的发布版 ...
- [NHibernate]存储过程的使用(二)
目录 写在前面 文档与系列文章 创建对象 更新对象 总结 写在前面 上篇文章介绍了如何使用MyGeneration代码生成器生成存储过程,以及nhibernate中通过存储过程删除数据的内容,这篇文章 ...
- noip2015 运输计划
描述 公元 2044 年,人类进入了宇宙纪元.L 国有 nn 个星球,还有 n−1n−1 条双向航道,每条航道建立在两个星球之间,这 n−1n−1 条 航道连通了 L 国的所有星球. 小 P 掌管一家 ...