HDU 3746:Cyclic Nacklace
Cyclic Nacklace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5663 Accepted Submission(s): 2557
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.
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
).
3
aaa
abca
abcde
0
2
5
#include <stdio.h>
#include <string.h>
char s[1000005];
int num[1000005];
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int j=-1;
num[0]=-1;
scanf("%s",s);
int n=strlen(s);
for(int i=0; i<n;)
{
if(j==-1||s[i]==s[j])num[++i]=++j;
else j=num[j];
}
int cir=n-num[n];
if(n%cir==0&&cir!=n)printf("0\n");
else printf("%d\n",cir-(n-(n/cir)*cir));
}
return 0;
}
HDU 3746:Cyclic Nacklace的更多相关文章
- HDU 3746:Cyclic Nacklace(KMP循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 模板题 + KMP + 求最小循环节 --- HDU 3746 Cyclic Nacklace
Cyclic Nacklace Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=3746 Mean: 给你一个字符串,让你在后面加尽 ...
- (KMP扩展 利用循环节来计算) Cyclic Nacklace -- hdu -- 3746
http://acm.hdu.edu.cn/showproblem.php?pid=3746 Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others ...
- 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 ...
- Cyclic Nacklace HDU - 3746 (kmp)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Cyclic Nacklace HDU 3746 KMP 循环节
Cyclic Nacklace HDU 3746 KMP 循环节 题意 给你一个字符串,然后在字符串的末尾添加最少的字符,使这个字符串经过首尾链接后是一个由循环节构成的环. 解题思路 next[len ...
- HDU 3746 Cyclic Nacklace(kmp next数组运用)
Cyclic Nacklace Problem Description CC always becomes very depressed at the end of this month, he ha ...
- Match:Cyclic Nacklace(KMP的next数组的高级应用)(HDU 3746)
串珠子 题目大意:给定一个字串,要你找到如果要使之成为循环串,在末尾需要的最小的字数(只能添加字符,不能删减字符) 首先联动一下之前做过的动态规划问题POJ 3280,当然了3280这一题是用的LD, ...
随机推荐
- HttpwebClient的四种请求方式
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷. 本文旨在发布代码,供自己参考,也供大家参考,谢谢. 正题: Ht ...
- 根据执行计划优化sql语句
优化前:表连接使用merge SQL> alter session set statistics_level=all; Session altered. SQL> select e.sal ...
- MySQL Replication的相关文件
1.master.info文件 位于slave端的数据目录下,存储slave连接到master的相关信息,如,master主机地址.连接用户.密码.端口.已经获取的日志信息. 复制过程中修改.删除ma ...
- MongoDB(一):安装
安装 从度娘上搜索MongoDB,找到官网地址:https://www.mongodb.com 找到下载中心地址:https://www.mongodb.com/download-center 我下载 ...
- ADO.net 防止SQL 字符串注入攻击
规避SQL注入 如果不规避,在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入Code值 p001' union select * from Info where '1'='1 //这样可 ...
- PHP Parse Error: syntax error, unexpected $end 错误的解决办
可以在php.ini中设置short_open_tag = On 第一步,登录到sql命令行 第二步,使用sql语句修改root密码 使用sql语句改密码时一定要选中数据库 .使用 use mys ...
- C++之路进阶——边表
边表:利用边的关系来表示一个图. 用到数组: head//head[i]表示从i点出发的第一条边的编号; next[i]//与第i条边起点相同的下一条边的编号; a[i]//第i条边的终点; val[ ...
- jsp页面指令
JSP中共有三个指令: (1)page: 用于定义JSP文件中的全局属性 (2)include: 用于在JSP页面中包含另外一个文件的内容 (3)taglib: 此指令能够让用户自定义新的标签 第三个 ...
- 复习课程jdbc:使用配置文件properties进行连接数据库,数据库存取图片,批处理,时间戳,事物回滚等等
使用配置文件properties进行连接数据库 首先创建一个file自定义文件名,但是后缀名必须改为.properties(不分大小写):如config.properties: 然后双击config. ...
- PHP漏洞全解(详细介绍)
转载 http://www.jb51.net/article/31898.htm 针对PHP的网站主要存在下面几种攻击方式: 1.命令注入(Command Injection) 2.eval注入(E ...