hdu 3746 Cyclic Nacklace KMP循环节
Cyclic Nacklace
题意:给一个长度为Len( 3 <= Len <= 100000 )的英文串,问你在字符串后面最少添加几个字符可以使得添加后的串为周期串?
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1e5 + ;
char p[N];
int f[N];
void getfail(char *p,int *f)
{
f[] = f[] = ;
int n = strlen(p);
for(int i = ;i < n;i++){
int j = f[i];
if(j && p[i] != p[j]) j = f[j];
f[i+] = (p[i] == p[j] ?j+:);// i+1会递推到第n位
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%s", p);
getfail(p,f);
int n = strlen(p),len = n - f[n];
if(f[n] && n%len == ) puts("");//本身就是周期串
else{
printf("%d\n",len-n%len);
}
}
}
hdu 3746 Cyclic Nacklace KMP循环节的更多相关文章
- hdu 3746 Cyclic Nacklace(kmp最小循环节)
Problem Description CC always becomes very depressed at the end of this month, he has checked his cr ...
- 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 (KMP求最小循环节)
//len-next[len]为最小循环节的长度 # include <stdio.h> # include <algorithm> # include <string. ...
- 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求循环节问题)
<题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题] #include &l ...
- HDU 3746 Cyclic Nacklace KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...
- 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求循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3746 Cyclic Nacklace(KMP找循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 题目大意:给你一个字符串,求出将字符串的最少出现两次循环节需要添加的字符数. 解题思路: 这题需 ...
随机推荐
- 再探ASP.NET 5(转载)
就在最近一段时间,微软又有大动作了,在IDE方面除了给我们发布了Viausl Studio 2013 社区版还发布了全新的Visual Studio 2015 Preview. Visual Stud ...
- Android市场官方的统计信息
做Android应用和游戏,避免不了的要了解市面上的各种android设备的信息,以最大程度的兼容更多的设备. Android市场会定期发布统计信息,包括SDK版本,屏幕大小和分辨率,OpenGL E ...
- Fast portable non-blocking network programming with Libevent--转
Learning Libevent Chapter 0: About this document Chapter 1: A tiny introduction to asynchronous IO. ...
- SerialPort基本小例
SerialPort是用于串口通信的控件与VB6中的MSCOMM控件相似,使用很方便... vb.net CodeImports System.IO.PortsImports System.TextP ...
- c/c++将整数转换为字符串
#include <iostream> using namespace std; int main(int argc, char **argv) { ; iint i,j; ],e[]; ...
- About Webkit
http://blog.csdn.net/spacetiller/article/details/5784461 一 . WebKit 简介 Webkit 是一个开放源代码的浏览器引擎 (web br ...
- Cstring到string
要利用mfc,然后接受一个图片. imread只能读const string& filename 的东西. imread 原型: CV_EXPORTS_W Mat imread( ); 它的参 ...
- git svn 简易同时使用
这个方法适合于新的一个git 仓库.假如你使用的git 是最新版本,git本身提供了 git svn命令. 1. 进入一个空的目录,初始化一个空的git仓库: git svn init svn://x ...
- php的递归函数
递归函数,就是在函数体内调用自身 例子: <?php function repayment($number){ if ($number<10){ echo $number." ...
- 【转】Oracle - 数据库的实例、表空间、用户、表之间关系
[转]Oracle - 数据库的实例.表空间.用户.表之间关系 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机 ...