HDU 2746 Cyclic Nacklace
Cyclic Nacklace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4420 Accepted Submission(s): 2011
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 ).
/* ***********************************************
Author :pk28
Created Time :2015/9/3 10:37:18
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; bool cmp(int a,int b){
return a>b;
}
char s[maxn];
int f[maxn],m;
void getFail(char *p,int *f){
m=strlen(p);
f[]=;f[]=;
for(int i=;i<m;i++){
int j=f[i];
while(j&&p[i]!=p[j])j=f[j];
f[i+]=p[i]==p[j]?j+:;
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--){
scanf("%s",s);
getFail(s,f);
int x=m-f[m];//循环节 的长度
if(f[m]!=&&m%x==){
printf("%d\n",);
}
else{
printf("%d\n",x-m%x);
}
}
return ;
}
HDU 2746 Cyclic Nacklace的更多相关文章
- 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 ...
- 模板题 + 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 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 ...
- 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 & 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】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu 3746 Cyclic Nacklace
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3746 思路:KMP中Next数组的应用,求出最小的循环节,题目的意思是只能在字符串的后面上添加新的字符 ...
随机推荐
- ElasticSearch API 之 GET
GET API是Elasticsearch中常用的操作,一般用于验证文档是否存在:或者执行CURD中的文档查询.与检索不同的是,GET查询是实时查询,可以实时查询到索引结果.而检索则是需要经过处理才能 ...
- linux的at定时任务的使用
linux的at定时任务的使用 使用at只能执行一次性任务:使用at命令需要开启atd进程. 以下情况需要安装at命令: 情况1.查看是否开启atd进程:ps -ef | grep atd.[test ...
- 每日记录 2016-4-29 HTML5本地存储
HTML5本地存储 一.HTML5 localStorage 在HTML5中,本地存储是一个window的属性,包括localStorage和 sessionStorage,从名字应该可以很清楚的辨认 ...
- delphi学习路线
酷派(53376063) 11:04:19 1.语法基础PASCAL精要 先看个1-3遍,这是基础中的基础,只要没弄清楚看10遍都不多,当然最好结合着代码实例去看.(以后遇到哪儿不熟练继续反复看)2 ...
- Invalid regular expression: unmatched parentheses
Unmatched ) in Javascript regular expression您的某些字符串包含错误')'.你需要逃避这个.这是这样做的功能: function escapeRegExp(s ...
- Mysql导出导入相关操作记录
一.使用source source sql脚本文件路径 二.使用mysqldump 命令行下具体用法如下: mysqldump -u用户名 -p密码 -d 数据库名 表名 脚本名; 1.导出数据库為 ...
- 学习日记之抽象工厂模式和Effective C++
抽象工厂模式(Abstract Factory):提供一个创建一系列相关或者相互依赖对象的接口.而无需制定他们详细的类. (1),工厂方法模式是定义一个用于创建对象的接口.让子类决定实例化哪一个类. ...
- STL源代码分析--deque
一.deque的中控器 deque是连续空间(至少逻辑上看来如此),连续线性空间总令我们联想到array或vector.array无法成长,vector虽可成长,却仅仅能向尾端成长.并且其 ...
- 用C++实现一个Log系统
提要 近期在写一些C++的图形代码,在调试和測试过程中都会须要在终端打印一些信息出来. 之前的做法是直接用 std::cout<<"Some Word"<< ...
- 性能測试JMeter趟的坑之JMeter的bug:TPS周期性波动问题
先说下问题: 我在做性能測试时,使用JMeter搞了100个并发,以100TPS的压力压測十分钟,但压力一直出现波动.并且出现波动时JMeter十分卡,例如以下图: 周期性TPS波动 各种猜測: 所以 ...