题目传送门

 /*
题意:一个串有字串重复n次产生,求最大的n
KMP:nex[]的性质应用,感觉对nex加深了理解
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-10 10:51:54
* File Name :POJ_2406.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
char str[MAXN];
int nex[MAXN]; int get_nex(void) {
int len = strlen (str);
int i = , j = -; nex[] = -;
while (i < len) {
if (j == - || str[j] == str[i]) {
j++; i++; nex[i] = j;
}
else j = nex[j];
}
if (i % (i - nex[i]) == ) {
return i / (i - nex[i]);
}
else return ;
} int main(void) { //POJ 2406 Power Strings
while (scanf ("%s", str) == ) {
if (str[] == '.') break;
printf ("%d\n", get_nex ());
} return ;
}

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

  1. poj 2406 Power Strings 后缀数组解法

    连续重复子串问题 poj 2406 Power Strings http://poj.org/problem?id=2406 问一个串能否写成a^n次方这种形式. 虽然这题用kmp做比较合适,但是我们 ...

  2. POJ 2406 Power Strings (KMP)

    Power Strings Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 29663Accepted: 12387 Descrip ...

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

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

  4. KMP + 求最小循环节 --- POJ 2406 Power Strings

    Power Strings Problem's Link: http://poj.org/problem?id=2406 Mean: 给你一个字符串,让你求这个字符串最多能够被表示成最小循环节重复多少 ...

  5. poj 2406:Power Strings(KMP算法,next[]数组的理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30069   Accepted: 12553 D ...

  6. poj 2406 Power Strings kmp算法

    点击打开链接 Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27368   Accepted:  ...

  7. poj 2406 Power Strings (后缀数组 || KMP)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28859   Accepted: 12045 D ...

  8. poj 2406 Power Strings(KMP变形)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28102   Accepted: 11755 D ...

  9. poj 2406 Power Strings(KMP入门,next函数理解)

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37685   Accepted: 15590 D ...

随机推荐

  1. 2018/2/15 ES Beats的学习笔记

    Beats其实是几种服务的统称(你也可以把收集到的数据存储到别的数据源,不一定非要ES),这几种服务分别是: 1.PacketBeat 通过抓包的方式来监控一些服务.如:HTTP,DNS,Redis, ...

  2. 可持久化KMP

    一开始有一空串,n次操作,每次在串末尾加入一个字符问最小循环节.要求在线与可持久化. 如果只是在线的话那是很简单的,答案是!!$i-fail[i]$,其中$fail[i]$是KMP中的失配函数. 但如 ...

  3. webstrom设置代码缩进四个空格

    言,今天在github上拉了一份代码,发现代码缩进是2个空格,不习惯.找到了解决方案. 一.File ---> Settings 搜索Code Style,取消勾选使用现文件的缩进方式,见下图. ...

  4. Minimum Depth of Binary Tree(二叉树DFS)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  5. mvn解决jar包冲突

    转自:http://blog.csdn.net/guanglihuan/article/details/50512855 对于Jar包冲突问题,我们开发人员经常都会有碰到,当我们使用一些jar包中的类 ...

  6. Systemtap工具查看系统资源使用

    http://www.xbwolf.com/507 http://blog.csdn.net/kafeiflynn/article/details/6429976 安装步骤yum install sy ...

  7. Ionic3错误记录:navigation stack needs at least one root page

    BUG场景:在 ActionSheetController 使用modalCtrl.create 创建模态框时报如下错误 原代码片段 解决方式: 重新设置root page

  8. Office高级威胁漏洞在野利用分析

    高级威胁漏洞背景 在高级威胁攻击中,黑客远程投递入侵客户端最喜欢的漏洞是office文档漏洞,就在刚刚结束不久的黑帽子大会上,最佳客户端安全漏洞奖颁给了CVE-2017-0199漏洞,这个漏洞是时下o ...

  9. firebug的应用

    firebug再前端调试中起到了非常好的作用能看到DOM的性能,以及检測.比方运用console.log()就是要比alert():好一些这样增强的页面的连续性而且console.warn()和con ...

  10. CentOS7.3编译安装Nginx设置开机启动

    起因 最近想玩nginx了,本来用yum -y install nginx安装也启动好了,但是买了本<Nginx高性能Web服务器详解>,我咋能辜负我的书费呢?于是我就直接ps -ef | ...