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 题目大意:给你一个字符串,求出将字符串的最少出现两次循环节需要添加的字符数. 解题思路: 这题需 ...
随机推荐
- PAT 1011
1011. World Cup Betting (20) With the 2010 FIFA World Cup running, football fans the world over were ...
- 写JQuery插件的基本知识
普及JQuery知识 知识1:用JQuery写插件时,最核心的方法有如下两个: 复制代码 代码如下: $.extend(object) 可以理解为JQuery 添加一个静态方法. $.fn.exten ...
- Templates
Templates Templates are the site's markup, where images and js, css files are located as well as the ...
- Asp.Net 之 汉字转拼音
1.利用微软提供的拼音库,计算出汉字的拼音的方法,此方法支持多音字符 下载 Visual Studio International Pack类库,该类库扩展了.NET Framework对全球化软件开 ...
- 210 - Concurrency Simulator(WF1991, deque, 模拟)
题目有点长,理解题花了不少时间 粘下别人的翻译~ 你的任务是模拟n个程序(按输入顺序编号为1~n)的并行执行.每个程序包含不超过25条语句,格式一共有5种: var=constant(赋值): pri ...
- 如何解决linux(ubuntu/CENTOS)中gedit中文乱码的问题
http://jingyan.baidu.com/article/1709ad80a443c54634c4f09c.html 同时按键盘的Alt 和 F2,就可以打开“运行程序”对话框,这个功能类似于 ...
- [记录]gulp compass
因为个人习惯用compass,所以gulp中,还是用compass进行编译scss文件. 1. 使用npm安装gulp-compass npm install gulp-compass --save- ...
- hadoop mapreduce 优化
http://www.cnblogs.com/c840136/archive/2013/03/10/2952887.html http://irwenqiang.iteye.com/blog/1535 ...
- 高级C#
使用delegates委托写插件方法: public delegate int Transformer (int x); public class Util { public static void ...
- 转--T-SQL 总结
把长日期转换为短日期 Convert(char(10),getdate(),120) MS-SQL数据库开发常用汇总 1.按姓氏笔画排序:Select * From TableName Orde ...