HDU 3746 Cyclic Nacklace (用kmp求循环节)
Cyclic Nacklace
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11516    Accepted Submission(s):
4913
month, he has checked his credit card yesterday, without any surprise, there are
only 99.9 yuan left. he is too distressed and thinking about how to tide over
the last days. Being inspired by the entrepreneurial spirit of "HDU CakeMan", he
wants to sell some little things to make money. Of course, this is not an easy
task.
As Christmas is around the corner, Boys are busy in choosing
christmas presents to send to their girlfriends. It is believed that chain
bracelet is a good choice. However, Things are not always so simple, as is known
to everyone, girl's fond of the colorful decoration to make bracelet appears
vivid and lively, meanwhile they want to display their mature side as college
students. after CC understands the girls demands, he intends to sell the chain
bracelet called CharmBracelet. The CharmBracelet is made up with colorful pearls
to show girls' lively, and the most important thing is that it must be connected
by a cyclic chain which means the color of pearls are cyclic connected from the
left to right. And the cyclic count must be more than one. If you connect the
leftmost pearl and the rightmost pearl of such chain, you can make a
CharmBracelet. Just like the pictrue below, this CharmBracelet's cycle is 9 and
its cyclic count is 2:
Now CC has brought in
some ordinary bracelet chains, he wants to buy minimum number of pearls to make
CharmBracelets so that he can save more money. but when remaking the bracelet,
he can only add color pearls to the left end and right end of the chain, that is
to say, adding to the middle is forbidden.
CC is satisfied with his ideas and
ask you for help.
< T <= 100 ) which means the number of test cases.
Each test case
contains only one line describe the original ordinary chain to be remade. Each
character in the string stands for one pearl and there are 26 kinds of pearls
being described by 'a' ~'z' characters. The length of the string Len: ( 3 <=
Len <= 100000 ).
count of pearls added to make a CharmBracelet.
aaa
abca
abcde
2
5
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
char a[];
int nxt[];
void get_next(int l)
{
int i = , j = -;
nxt[] = -;
while (i != l)
{
if (j == - || a[i] == a[j])
{
i++;
j++;
nxt[i] = j;
}
else
j = nxt[j];
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
scanf("%s", a);//居然用cin>>a就wa了
int m = strlen(a);
get_next(m);
int n = m - nxt[m];//代表循环节的长度
if (n != m && m%n == )printf("0\n");//如果可以多次循环
else printf("%d\n", n - nxt[m] % n);//取余的作用:abcab,去掉abc
}
return ;
}
HDU 3746 Cyclic Nacklace (用kmp求循环节)的更多相关文章
- HDU 3746 Cyclic Nacklace(KMP+最小循环节)题解
		思路: 最小循环节的解释在这里,有人证明了那么就很好计算了 之前对KMP了解不是很深啊,就很容易做错,特别是对fail的理解 注意一下这里getFail的不同含义 代码: #include<io ... 
- hdoj 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 题目大意:给你一个字符串,求出将字符串的最少出现两次循环节需要添加的字符数. 解题思路: 这题需 ... 
- hdu  3746  Cyclic Nacklace(KMP)
		题意: 求最少需要在后面补几个字符能凑成两个循环. 分析: 最小循环节的应用,i-next[i]为最小循环节. #include <map> #include <set> #i ... 
- HDU - 3374 String Problem (kmp求循环节+最大最小表示法)
		做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ... 
- HDU 3746 Cyclic Nacklace (KMP求循环节问题)
		<题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题] #include &l ... 
- HDU 3746 Cyclic Nacklace(kmp next数组运用)
		Cyclic Nacklace Problem Description CC always becomes very depressed at the end of this month, he ha ... 
- 模板题 + 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中next数组的使用 好题!!!)
		Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ... 
随机推荐
- noip2018 爆炸记
			noip2018 爆炸记 day-4 ~ day-2 最后考了两套模拟题,题目好水啊,但是我还是爆炸了. 第一套最后一道题竟然时一道毒瘤打表?但是我看着插头DP可做啊..(然而我并不会插头DP)然后还 ... 
- API设计原则(觉得太合适,转发做记录)
			API设计原则 对于云计算系统,系统API实际上处于系统设计的统领地位,正如本文前面所说,K8s集群系统每支持一项新功能,引入一项新技术,一定会新引入对应的API对象,支持对该功能的管理操作,理解掌握 ... 
- HDU 4183 Pahom on Water(最大流)
			https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频 ... 
- Pro Git读书笔记 - Git 常用命令
			在工作目录中初始化新仓库 要对现有的某个项目开始用 Git 管理,只需到此项目所在的目录,执行git init 检查当前文件状态 要查看哪些文件处于什么状态,可以用git status命令 将工作文件 ... 
- C#中标准Dispose模式的实现(转载)
			需要明确一下C#程序(或者说.NET)中的资源.简单的说来,C#中的每一个类型都代表一种资源,而资源又分为两类: 托管资源:由CLR管理分配和释放的资源,即由CLR里new出来的对象: 非托管资源:w ... 
- CentOS6.4_x86_120g__20160306.rar
			安装的镜像包: CentOS-6.4-i386-bin-DVD1to2(CentOS-6.4-i386-bin-DVD1.iso / CentOS-6.4-i386-bin-DVD2.iso) 1. ... 
- VNC Viewer连接Cent OS 时的 复制粘帖 功能
			虽然 VNC Viewer 比起 vsphere Client 来, 感觉性能差一点. 但毕竟也是个选择. 找了一下 它的这个 功能. 运行一下 vncconfig & 就可以了. 实测好用. ... 
- Spring4 MVC RESTFul WebServices CRUD实例+RestTemplate
			简单介绍REST REST 表示状态传输.这是一个体系结构样式,可用于设计网络服务,可以被各种客户端消耗.核心思想是,不使用如CORBA,RPC或SOAP复杂的机制在机器之间进行连接,简单的 HTTP ... 
- React中使用UEditor
			一般UEditor用于表单的新建和编辑 <FormItem {...formItemLayout} label='商品详情'> {getFieldDecorator('detail', { ... 
- JavaScript学习总结(二十二)——JavaScript屏蔽Backspace键
			今天在IE浏览器下发现,当把使用readonly="readonly"属性将文本框设置成只读<input type="text" readonly=&qu ... 
