F - Power Strings

Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

Input

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s you should print the largest n such that s = a^n for some string a.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.
 
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define maxn 10010000
using namespace std;
char p[maxn];
int next[maxn],len;
int kmp(){
int i=,j=-;
next[]=-;
while(i<len){
if(j==-||p[i]==p[j]) next[++i]=++j;
else j=next[j];
}
}
int main()
{
while(scanf("%s",p)!=EOF&&p[]!='.'){
len=strlen(p);
kmp();
if(len%(len-next[len]))printf("1\n");
else printf("%d\n",len/(len-next[len]));
}
return ;
}

POJ 2406 Power Strings的更多相关文章

  1. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  2. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

  3. poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)

    http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submiss ...

  4. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

  5. KMP + 求最小循环节 --- POJ 2406 Power Strings

    Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...

  6. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  7. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

  8. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

  9. poj 2406 Power Strings(KMP变形)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 D ...

随机推荐

  1. Java中的守护线程和非守护线程(转载)

    <什么是守护线程,什么是非守护线程> Java有两种Thread:"守护线程Daemon"(守护线程)与"用户线程User"(非守护线程). 用户线 ...

  2. cocospods的安装与应用

    安装cocospods 一,升级Ruby环境 ~ xxx$ sudo gem update --system   二,安装Cocoapods时需要访问cocoapods.org,该网站可能被墙掉,但是 ...

  3. 如何发布得到.ipa文件

    第一个方法: 如果都有证书的话,并且又不想把别人的机器添加到测试设备中,或者感觉获取UDID麻烦的话,那么就可以采用该方法了. 直接Archive应用程序: 右键显示包内容到product下复制里面的 ...

  4. Effective Java 38 Check parameters for validity

    For public methods, use the Javadoc @throws tag to document the exception that will be thrown if a r ...

  5. Memcache限制端口和访问IP

    Memcache安装十分简单,默认情况下是任何人都可以访问服务器上缓存的数据,所以如果不作处理的话 是很不安全的(乌云上已经提交有很多与此相关的问题) 1.首先要保证服务器上的防火墙都是开启的 2.设 ...

  6. SharePoint 指定配置数据库访问账户“域账户\用户”

    大家在安装sharepoint时都会遇到这个问题,域账户,什么是域账户哪?域账户简单理解就是网路账户,与本地账户不同,什么是域哪?域就是控制器. 一台Windows 计算机,它要么隶属于工作组,要么隶 ...

  7. PL/SQL之--存储过程

    一.存储过程 存储过程是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它.oracle可以把PL/SQL程序储存在数 ...

  8. mac下 home-brew安装及php,nginx环境安装及配置

    Homebrew官网 http://brew.sh/index_zh-cn.html Homebrew是神马 linux系统有个让人蛋疼的通病,软件包依赖,好在当前主流的两大发行版本都自带了解决方案, ...

  9. linux 下安装nodejs,CentOS 6.5 系统

    本文采用nodejs 通过源码编译安装方式 编译需要gcc-c++编译器和openssl-devel库的支持,如果没有需要先安装. 在centos下可以先执行:yum install gcc-c++ ...

  10. git_sop 脚本使用说明

    tags : git 前言 脚本下载地址: git是功能非常强大的版本管理工具,同时它带来的是学习成本的上升.最近我们团队的部分项目采用了git进行版本管理,一部分小伙伴对于git使用不是很熟悉.一方 ...