Power Strings POJ - 2406
时限: 3000MS | 内存: 65536KB | 64位IO格式: %I64d & %I64u |
问题描述
输入
输出
样例输入
abcd
aaaa
ababab
.
样例输出
1
4
3
提示
来源
#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的更多相关文章
- ( KMP 求循环节的个数)Power Strings -- poj -- 2406
链接: http://poj.org/problem?id=2406 Power Strings Time Limit:3000MS Memory Limit:65536KB 64bi ...
- Power Strings (poj 2406 KMP)
Language: Default Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33205 ...
- Power Strings POJ - 2406 后缀数组
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- Match:Power Strings(POJ 2406)
字符串前缀的阶 题目大意:求前缀的阶 和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的) #include <iostream> ...
- Power Strings - POJ 2406(求循环节)
题目大意:叙述的比较高大上,其实就是一个字符串B = AAAAAAA,求出来这个A最短有多长 分析:注意如果这个串不是完全循环的,那么循环节就是就是它本身. 代码如下: #include< ...
- Power Strings POJ - 2406(next水的一发 || 后缀数组)
后缀数组专题的 emm.. 就next 循环节../ 有后缀数组也可以做 从小到大枚举长度i,如果长度i的子串刚好是重复了len/i次,应该满足len % i == 0和rank[0] - rank[ ...
- 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中的出现位置或者是次数 这个出现的次数是可 ...
- POJ 2406 Power Strings
F - Power Strings Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- poj 2406 Power Strings (kmp 中 next 数组的应用||后缀数组)
http://poj.org/problem?id=2406 Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- python正则表达式整理
正则表达式在处理字符串时很大的作用,爬虫中也经常用到,下面就将一些常用正则表达式做一整理记录,方便以后查看. ^d 表示匹配以d开头的字符串 . 表示匹配任意字符串 * 表示前面 ...
- Python笔记(二十八)_魔法方法_迭代器
迭代器用于遍历容器中的数据,但它不是容器,它是一个实现了__next__方法的对象 与迭代器相关的内置函数: iter(): 将一个对象转换成一个迭代器 next(): 访问迭代器中的下一个变量,直到 ...
- Nginx配置之rewrite、proxy_pass、upstream、location
如图,这是Nginx的配置文件nginx.conf中的一段配置代码. 在http段中定义了一个名为webservers的upstream模块,主要用于负载均衡. 在server模块中,定义了一个loc ...
- [Web 前端] 018 css 清除浮动的四种方法
清除浮动的四种方法 加 clear: ...(见例1) 父级上增加属性 overflow:hidden(见例2.1) 在最后一个子元素的后面加一个空的 div,给它一个样式属性 clear: both ...
- from 表单回车自动提交
自动提交的情况 1 表单只有单个输入框 2 type=‘submit 这里注意button默认type为submit 解决方法 1 添加一个隐藏的输入框 2 form添加属性 onsubmit=&q ...
- PPT制作,数据图等画图
1. mathcad 画图简单不错 2.三维图 matlab不错 3.PPT 学术ppt,美观明了,思路清晰,数据可视化 学术PPT: http://mp.weixin.qq.com/s/TPYW ...
- SUSTOJ_路痴的单身小涵(图中最短路的条数)
去年因为太low没有做出来校赛的最后一题,遂今年校赛做了这个题,下面我做详细描述. 原题链接 本题大意:给定一个无向图G,每个边的权值为1,图中L表示起点,C表示终点,#表示未通路,给定时间k,让你判 ...
- 数据分析之pandas(1)
一.Pandas的数据结构 1.Series (1)类似于一维数组 (2)通过list构建Series ser_obj=pd.Series(range(10)) (3)pandas数据结构案例
- http请求中的Content-Length作用机制与分块chunked
httpclient-4.5.9.jar org.apache.http: auth 身份 client 端 conn 连接 cookie 本地 impl: 实现 exe ...
- MongoDB的使用学习之(三)安装MongoDB以及一些基础操作
原文链接:http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html 此博主的 8天学通MongoDB 系列还是不错的,本 ...