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. JavaScript 基础类型,数据类型

    1.基础类型:undefined,null,Boolean,Number,String,Symbol Undefined类型:一个没有被赋值的变量会有个默认值undefined; Null类型:nul ...

  2. hbase报错之 Master is initializing

    报错日志 ERROR: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing at org.apache.hadoop ...

  3. 初探LINUX之--基础知识篇

    一 Linux哲学思想 1 一切都是一个文件(包含硬件) 2 小型,单一用途的程序 3 链接程序,共同完成复杂的任务 4 避免令人困惑的用户界面 5 配置数据存储在文本中 二 Linux重要概念 Sh ...

  4. Numerical Sequence (easy version)

    http://codeforces.com/problemset/problem/1216/E1 E1. Numerical Sequence (easy version) time limit pe ...

  5. 洛谷 - P4567 - 文本编辑器 - 无旋Treap

    https://www.luogu.org/problem/P4567 事实证明无旋Treap是不是不可能会比Splay快? #include<bits/stdc++.h> using n ...

  6. 汇编移位: SHL、SHR、SAL、SAR、ROL、ROR、RCL、RCR

    SHL.SHR.SAL.SAR: 移位指令 ;SHL(Shift Left):      逻辑左移 ;SHR(Shift Right):      逻辑右移 ;SAL(Shift Arithmetic ...

  7. JUC并发包基本使用

    一.简介 传统的Java多线程开发中,wait.notify.synchronized等如果不注意使用的话,很容易引起死锁.脏读问题.Java1.5 版本开始增加 java.util.concurre ...

  8. django学习笔记(二)

    上节内容回顾: 1.Django请求生命周期 -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串 -> URL对应关系(匹配) -> 视图函数 -> ...

  9. JVM 运行时数据区域划分

    目录 前言 什么是JVM JRE/JDK/JVM是什么关系 JVM执行程序的过程 JVM的生命周期 JVM垃圾回收 JVM的内存区域划分 一.运行时数据区包括哪几部分? 二.运行时数据区的每部分到底存 ...

  10. 安装运行谷歌开源的TensorFlow Object Detection API视频物体识别系统

    Linux安装 参照官方文档:https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/inst ...