链接:

http://poj.org/problem?id=2406

Power Strings

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

Submit Status

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<stdio.h>
#include<string.h>
#include<stdlib.h> #define N 1000007 char S[N];
int Next[N]; /// Next中存的是前缀和后缀的最大相似度 void FindNext(int Slen, int Next[]) ///Next[i] 代表前 i 个字符的最大匹配度
{
int i=, j=-;
Next[] = -; while(i<Slen)
{
if(j==- || S[i]==S[j])
Next[++i] = ++j;
else
j = Next[j];
}
} int main()
{
while(scanf("%s", S), strcmp(S, "."))
{
int Slen=strlen(S); FindNext(Slen, Next); if(Slen%(Slen-Next[Slen]))
printf("1\n");
else
printf("%d\n", Slen/(Slen-Next[Slen]));
} return ;
}
 

( KMP 求循环节的个数)Power Strings -- poj -- 2406的更多相关文章

  1. HDU 3746 Cyclic Nacklace (KMP求循环节问题)

    <题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题]  #include &l ...

  2. Power Strings POJ - 2406

    Power Strings POJ - 2406 时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Gi ...

  3. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

  4. HDU - 3374 String Problem (kmp求循环节+最大最小表示法)

    做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...

  5. Power Strings (poj 2406 KMP)

    Language: Default Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33205   ...

  6. Power Strings - POJ 2406(求循环节)

    题目大意:叙述的比较高大上,其实就是一个字符串B = AAAAAAA,求出来这个A最短有多长   分析:注意如果这个串不是完全循环的,那么循环节就是就是它本身.   代码如下: #include< ...

  7. Power Strings POJ - 2406 后缀数组

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  8. Power Strings POJ - 2406(next水的一发 || 后缀数组)

    后缀数组专题的 emm.. 就next 循环节../ 有后缀数组也可以做 从小到大枚举长度i,如果长度i的子串刚好是重复了len/i次,应该满足len % i == 0和rank[0] - rank[ ...

  9. Match:Power Strings(POJ 2406)

     字符串前缀的阶 题目大意:求前缀的阶 和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的) #include <iostream> ...

随机推荐

  1. 【转】Java自学之路——by马士兵

    作者:马士兵老师 JAVA自学之路 一:学会选择 为了就业,不少同学参加各种各样的培训. 决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机.嵌入式.游戏.3G.测试等. 那么究竟 ...

  2. PostgreSql别名区分大小写的问题

    PostgreSql是区分大小写的,如果别名的大小不一致就会提示错误: SELECT * FROM ( SELECT cpi."product_item_id" "PRO ...

  3. Haskell语言学习笔记(36)Data.List.Zipper

    ListZipper 模块 $ cabal install ListZipper Installed ListZipper-1.2.0.2 Prelude> :m +Data.List.Zipp ...

  4. 常用类一一基本数据类型的包装类(WrapperClass)一一Byte Short nteger Long Float Double Character Boolean

    为什么需要包装类? JAVA是支持跨平台的.可以在服务器 也可以在手机上运行 基本数据类型 在栈中  效率更高 包装类 将数据类型转换成对象 在 堆中  利于操作 package cn.bjsxt.w ...

  5. Elon Musk

    人物事件 成长学习 年6月28日,埃隆·马斯克在南非的比勒陀利亚出生,他的 埃隆·马斯克 父亲是一名南非机电工程师,母亲是加拿大人,从事营养师兼模特.[8]  年,10岁的马斯克就拥有了自己的第一台电 ...

  6. Linux运维就业技术指导(九)期末架构考核

    一,毕业架构设计考核筹备 1.1,架构图模板示例 1.1.1 架构图(一)概述 本架构是4层lvs负载均衡给后方7层nginx反向代理: 业务进行了动静分离: 数据库前端有memcached缓存组,降 ...

  7. Linux就业技术指导(三):IDC机房解密

    1.1 IDC机房 1.1.1 带宽计算 带宽流量计算公式: 1 Byte=8bit,1KB=1024B,1MB=1024KB,1GB=1024MB B表示Byte,工业标准是1000. 一般我们家装 ...

  8. js 获取input选择的图片的信息

    1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...

  9. lua 中的点、冒号与self

    [lua 中的点.冒号与self] lua编程中,经常遇到函数的定义和调用,有时候用点号调用,有时候用冒号调用. girl = {money = 200} function girl.goToMark ...

  10. Xcrysden-2

    XCrySDen -- (X-Window) CRYstalline Structures and DENsities Introduction to use. XCrySDen is a cryst ...