HDU——T 3746 Cyclic Nacklace
http://acm.hdu.edu.cn/showproblem.php?pid=3746
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9975 Accepted Submission(s): 4267
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 ).
aaa
abca
abcde
2
5
#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N(+);
int len,p[N],ans;
char s[N]; inline void Get_next()
{
for(int j=,i=;i<=len;i++)
{
for(;j>&&s[i]!=s[j+];) j=p[j];
if(s[i]==s[j+]) j++;
p[i]=j;
}
} int main()
{
int t;scanf("%d",&t);
for(;t--;)
{
scanf("%s",s+);
len=strlen(s+);
memset(p,,sizeof(p));
Get_next();
ans=len-p[len];
for(int tmp=ans;ans<len;) ans+=tmp;
if(!p[len]) printf("%d\n",ans);
else printf("%d\n",ans-len);
}
return ;
}
HDU——T 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 ...
- 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 & 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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 思路:KMP中Next数组的应用,求出最小的循环节,题目的意思是只能在字符串的后面上添加新的字符 ...
- HDU 3746 Cyclic Nacklace KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...
随机推荐
- numpy中list array matrix比较
用python中的numpy包的时候不小心踩了array和matrix的大坑,又引申一下比较list array matrix之间的异同.数据结构(Data Structures)基本上人如其名——它 ...
- Unity WebGL 窗口自适应
unity 打包好WebGL后,用文本编辑器编辑打包生成的 index.html 文件 在生成的html里面修改代码 <script type="text/javascript ...
- Unity Shader (四)片段程序示例
1.环境光+漫反射+高光+点光源 Shader "Custom/Example_Frag_1" { properties { _MainColor(,,,) _Specular ...
- Python安装selenium启动浏览器
1:在Python运行火狐或谷歌的浏览器是需要下载相对应的驱动 例如:你想在Python中使用代码命令打开firefox的网页 如果没有安装驱动,直接运行的话会出下面的错误 所以我们要安装相对应的浏览 ...
- 09-breack语句
- 已知二叉树的中序序列为DBGEAFC,后序序列为DGEBFCA,给出相应的二叉树
面对这种问题时我们该怎么解决? 今天写数据结构题.发现了一道总是碰见问题的题在这里我写了一种求解方法我自己称它为分层递归求解. 第一步通过观察我们知道后序遍历时最后一个是根节点A 在中序序列中A的左边 ...
- vue8 生命周期
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 理解FPGA中的RAM、ROM和CAM;ROM、RAM、DRAM、SRAM、FLASH
目前大多数FPGA都有内嵌的块RAM(Block RAM),可以将其灵活地配置成单端口RAM(DPRAM,Single Port RAM).双端口RAM(DPRAM,Double Ports RAM) ...
- WebForms简介
http://www.w3school.com.cn/aspnet/aspnet_intro.asp ASP.NET 是下一代 ASP,不是 ASP 的更新版本. https://docs.micro ...
- 8.不绑定(ngNonBindable)
转自:https://www.cnblogs.com/best/tag/Angular/ ngNonBindable指令告诉Angular编译或绑定当前DOM元素的内容.这对于要求Angular忽略那 ...