Power Strings

POJ - 2406
时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u

提交 状态

已开启划词翻译

问题描述

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).

输入

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.

输出

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

样例输入

abcd
aaaa
ababab
.

样例输出

1
4
3

提示

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

来源

题意:一个字符串可以由其循环节循环n次得到,问n最大可以是多少……
kmp练习。
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; #define maxn 10000008 char s[maxn];
int next[maxn]; void getNext()
{
int j, k, i;
i = strlen(s); j = ;
k = -;
next[] = -;
while(j < i)
{
if(k == - || s[j] == s[k])
{
j++;
k++;
next[j] = k;
}
else
k = next[k];
}
} int main()
{
while()
{
scanf("%s", s);
if(s[] == '.')
break; int q = strlen(s); memset(next, , sizeof(next));
getNext(); int k = next[q]; // k表示s串 q位置的最长的前缀和后缀相等的长度。q-k代表最小循环节的长度 if(q % (q - k) == ) // q-k就是最小循环节的长度
printf("%d\n", q / (q - k));
else
printf("1\n");
}
return ;
}

Power Strings POJ - 2406的更多相关文章

  1. ( KMP 求循环节的个数)Power Strings -- poj -- 2406

    链接: http://poj.org/problem?id=2406 Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bi ...

  2. Power Strings (poj 2406 KMP)

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

  3. Power Strings POJ - 2406 后缀数组

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

  4. Match:Power Strings(POJ 2406)

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

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

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

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

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

  7. KMP——POJ-3461 Oulipo && POJ-2752 Seek the Name, Seek the Fame && POJ-2406 Power Strings && POJ—1961 Period

    首先先讲一下KMP算法作用: KMP就是来求在给出的一串字符(我们把它放在str字符数组里面)中求另外一个比str数组短的字符数组(我们叫它为ptr)在str中的出现位置或者是次数 这个出现的次数是可 ...

  8. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

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

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

随机推荐

  1. 《Using Python to Access Web Data》 Week3 Networks and Sockets 课堂笔记

    Coursera课程<Using Python to Access Web Data> 密歇根大学 Week3 Networks and Sockets 12.1 Networked Te ...

  2. oracle 11g 数据库恢复技术 ---02 控制文件

    oracle 11g 数据库恢复技术 ---02 控制文件 SYS@ orcl >show parameter control_file NAME TYPE VALUE ------------ ...

  3. Hadoop and Big Data

    Hadoop(1): HDFS Basics Hadoop(2):HDFS Block Management Hadoop(3): Prepare inputs for MapReduce mappe ...

  4. 倾旋之slack主题协同

    源:https://pocketcorp.slack.com/join/shared_invite/enQtNTk2MDYwNDA4NzU0LTg3ZGVlNDE5NWUzNjJhZTc1MDQ5MT ...

  5. xmake-vscode插件开发过程记录

    最近打算给xmake写一些IDE和编辑器的集成插件,发现vscode的编辑器插件比较容易上手的,就先研究了下vscode的插件开发流程,并且完成了xmake-vscode插件的开发. 我们先来看几张最 ...

  6. Mybatis-基本步骤

    1.1Mybatis框架概述 Mybatis是基于Java的持久层框架,内部封装了jdbc,使开发者只需关注sql语句本身,而不需要花费精力去处理加载驱动.创建连接.创建Statement等繁杂的过程 ...

  7. BitMap的原理和实现

    相关概念 基础类型 在java中: byte -> 8 bits -->1字节 char -> 16 bit -->2字节 short -> 16 bits --> ...

  8. js去掉输入框的前后空格及一些常用正则表达式

    去掉TextBox输入框两头的前后空格:onblur="this.value=this.value.replace(/^\s+|\s+$/g,'');" str为要去除空格的字符串 ...

  9. vue-router的hash和history模式的区别

    一.概念 为了构建 SPA(单页面应用),需要引入前端路由系统,这也就是 Vue-Router 存在的意义. 前端路由的核心,就在于:改变视图的同时不会向后端发出请求. 为了达到这种目的,浏览器当前提 ...

  10. linux开启 Sersync 守护进程进行数据同步

    a.配置 Sersync 环境变量 [root@SERSYNC sersync]# echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/et ...