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. VS2012下自定义打开文件对话框

    VS2012下自定义打开文件对话框,MFC的CFileDialog封装了太多,太复杂,绕得头晕,自己封装一个得了 #pragma once #include <objbase.h> #in ...

  2. 新手解惑:nginx&php-fpm&fastcgi 是什么关系

    首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者.   web server(比如说nginx)只是内容的分发者.比如,如果请求/index ...

  3. 练习2:python-把excel表格中某张表的内容导入sqlite

    前言:最新需要用到大批量的数据,在excel造好数据之后,存储在数据库库中,方便调用数据,于是就想着用python语言写一下这个过程 python有个openpyxl的模块,可以直接用来对于excel ...

  4. bootstrap-select控件全选,全不选,查询功能实现

    先引入先在你的页面引入 bootstrap-select.css 和 bootstrap-select.js <link href="~/Content/plugins/bootstr ...

  5. review-1

    # ### for 循环和序列的运用 # remember = ['从入门到放弃', '从入门到如土', 123, 'happy']# for each in remember:# print(eac ...

  6. rac节点挂掉后,vip飘到别的节点,但是业务连接不上报 no listener问题处理

    客户一套rac系统,三节点,其中一个节点的p260主机主板有问题(经常机器重启,好像是这个型号的通病,主板被炒到20W),临时把故障节点的vip作为业务地址用. 首先,查看确定故障节点vip飘到那个节 ...

  7. Apache httpclient拦截器对请求进行签名

    Apahce httpclient 提供HttpRequestInterceptor和HttpResponseInterceptor两种拦截器分别处理请求和响应数据,下面讲一下如何对http请求进行拦 ...

  8. C#中Func与Action的理解

    Action 与 Func是.NET类库中增加的内置委托,以便更加简洁方便的使用委托.最初使用委托时,均需要先定义委托类型,然后定义一个符合委托类型签名的函数,在调用前,需声明并创建委托对象,将指定函 ...

  9. git 中添加用户名和密码

    git 中添加用户名和密码:https://blog.csdn.net/qq_28602957/article/details/52154384 在使用git时,如果用的是HTTPS的方式,则每次提交 ...

  10. weight (搜索对象的选取)

    #10249. 「一本通 1.3 例 5」weight [题目描述] 已知原数列 $a_1,a_2,\cdots,a_n$​​ 中的前 1项,前 2 项,前3项, $\cdots$ ,前 n 项的和, ...