E - Power Strings,求最小周期串
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3 讲了这么多,其实就是一个求一个字符串里最小周期的问题。限时有3S,我们可以用枚举。
这里需要注意的是一个:求周期串的基本算法:
for(i=1;i<=len;i++)
{
ok=1;
if(len%i==0)
{
for(j=i;j<len;j++)
{
if(s[j]!=s[j%i]){ok=0;break;}
}
}
if(ok==1)
{
printf("%d\n",len/i);
break;//记得要break
}
}
#include<cstdio>
#include<string.h>
using namespace std;
char s[];
int main()
{
while(scanf("%s",s)==&&strcmp(s,".")!=)
{
int len=strlen(s); for(int i=;i<=len;i++)
if(len%i==)
{
int ok=;
for(int j=i;j<len;j++)
{
if(s[j]!=s[j%i])
{
ok=;
break;
}
}
if(ok)
{
printf("%d\n",len/i);
break;
} }
}
return ;
}
E - Power Strings,求最小周期串的更多相关文章
- 【KMP求最小周期】POJ2406-Power Strings
[题意] 给出一个字符串,求出最小周期. [思路] 对KMP的next数组的理解与运用orz ①证明:如果最小周期不等于它本身,则前缀和后缀必定有交叉. 如果没有交叉,以当前的next[n]为最小周期 ...
- UVa455 最小周期串问题
A character string is said to have period k if it can be formed by concatenating one or more repetit ...
- poj 2406 Power Strings【最小循环节】
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36926 Accepted: 15254 D ...
- (字符串的模式匹配4.7.18)POJ 2406 Power Strings(求一个字符串的最小重复串)
注意,在IDE运行时,可能会因为开的数组太大而报错,这时我们可以把数组开小一点来进行调试....提交的时候把数组的大小改成1000005即可.... #include <iostream> ...
- Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...
- poj2406 Power Strings (kmp 求最小循环字串)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 47748 Accepted: 19902 ...
- KMP + 求最小循环节 --- POJ 2406 Power Strings
Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...
- POJ--2406Power Strings+KMP求字符串最小周期
题目链接:点击进入 事实上就是KMP算法next数组的简单应用.假设我们设这个字符串的最小周期为x 长度为len,那么由next数组的意义,我们知道len-next[len]的值就会等于x.这就是这个 ...
- poj2406--Power Strings(KMP求最小循环节)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33178 Accepted: 13792 D ...
随机推荐
- SqlFunctions 可以在EF种调用sqlserver的函数
在EF5环境下,首先添加EF环境,在引用中添加Syste.Data.Entity,再添加命名空间 using System.Data.Objects.SqlClient; 然后写一个控制器测试 pub ...
- MongoDB相关资料
MongoDB的介绍及安装参考http://www.cnblogs.com/lipan/archive/2011/03/08/1966463.html 安装过程: 第一步:下载安装包:官方下载地址←单 ...
- Jquery select 选中项中自定义的值
给select 赋值,除了已有的value及text,新建一属性simple_name function GetDicOfficeList(dicType, sid) { $.ajax({ url: ...
- Windows API调用外部程序
要在应用程序中启动其他的应用程序,有3个函数可以使用,下面我一一说说他们(我以打开D:\Program Files\zeecalls\目录下的zeecalls.exe应用程序为例): 1.Winexe ...
- Jquery API Hybrid APP调研
http://jquery.cuishifeng.cn/source.html hybrid app Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间 ...
- 10 notorious computer virus
The history of computer virus is the same as computer history. With more and more powerful computers ...
- POJ 1860 Currency Exchange 最短路 难度:0
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...
- django.test.client 使用随记
import os,sys,django; sys.path.append("\\path\\to\\mysite")#ATTETION!,Err: "unable to ...
- JSON.NET 教程(一)
下载地址:http://www.newtonsoft.com/json 参考官网文档:http://www.newtonsoft.com/json/help/html/SerializingJSON. ...
- ros科大讯飞语音识别环境配置
以在线命令词识别为例: 链接:http://www.xfyun.cn/sdk/dispatcher 1.下载SDK,解压: 2.在ROS工作空间下创建一个Package: catkin_create_ ...