题目链接:http://poj.org/problem?id=2406

题意:确定字符串最多是多少个相同的字串重复连接而成的

思路:关键是找到字符串的最小循环节

code:

 #include <cstdio>
#include <cstring>
const int MAXN = ;
char s[MAXN];
int next[MAXN];
void GetNext()
{
int len = strlen(s);
int i = ;
int j = -;
next[] = -;
while (i < len)
{
if (- == j || s[i] == s[j]) next[++i] = ++j;
else j = next[j];
}
} int main()
{
while (scanf("%s", s), s[] != '.')
{
int len = strlen(s);
GetNext();
if (len % (len - next[len]) == ) printf("%d\n", len / (len - next[len]));
else printf("1\n");
}
return ;
}

POJ 2406 Power Strings(字符串的最小循环节)的更多相关文章

  1. POJ 2406 - Power Strings - [KMP求最小循环节]

    题目链接:http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Description Given two st ...

  2. poj 2406 Power Strings【字符串+最小循环节的个数】

                                                                                                      Po ...

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

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

  4. KMP POJ 2406 Power Strings

    题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...

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

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

  6. 【kmp+最小循环节】poj 2406 Power Strings

    http://poj.org/problem?id=2406 [题意] 给定字符串s,s=a^n,a是s的子串,求n最大是多少 [思路] kmp中的next数组求最小循环节的应用 例如 ababab ...

  7. poj 2406 Power Strings【最小循环节】

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36926   Accepted: 15254 D ...

  8. POJ 2406 Power Strings next数组循环节应用、

    题意:就给出个字符串做*的定义.a^0 = "" (the empty string) and a^(n+1) = a*(a^n).    题目要求n的最大值. 思路: 化简上面的 ...

  9. POJ 2406 Power Strings (KMP)

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

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

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

随机推荐

  1. IOS深入学习(1)之图标文件(icon files)

    1 前言 我相信大家在做IOS一定经常会跟图标文件(icon files)打交道,今天我们就来简单的学习一下iPhone和iPad程序中的icon files. 2 详述 除了iTunesArtwor ...

  2. MojoliciousLite: 实时的web框架 概述

    MojoliciousLite: 实时的web框架: SYNOPSIS 简介: # Automatically enables "strict", "warnings&q ...

  3. [Leetcode][Python]28: Implement strStr()

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...

  4. thunk的主要用法

    主要用法目前用的多的就三种; thunk.all 并发 thunk.sql 同步 thunk.race 最先返回的进入结果输出 前两个返回的结果都是数组,最后一个返回的是对象: thunk的链式调用没 ...

  5. 加入收藏夹的js代码(求兼容chrome浏览器的代码)

    从网上找了加入收藏夹的js代码,但不兼容chrome,不知道有没有兼容chrome的相关代码,希望有知道的告诉一下,谢谢! 代码如下 $("#id").click(function ...

  6. 适配iPad的操作表sheet

    在 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"上传文件" message:@ ...

  7. BigDecimal类的简单使用方法

    一提到Java里面的商业计算,我们都知道不能用float和double,由于他们无法进行精确计算.可是Java的设计者给编程人员提供了一个非常实用的类BigDecimal,他能够完好float和dou ...

  8. elmah - Error Logging Modules and Handlers for ASP.NET - 1 : 初体验

    elmah(英文):https://code.google.com/p/elmah/   写作思路:先看结果,然后再说原理   elmah文章基本内容如下   1.安装 2.基本使用 3.详细配置讲解 ...

  9. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (三) —— SharePreferences

    除了SQLite数据库外,SharedPreferences也是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息.其存储位置在/data ...

  10. ##DAY9 UITabBarController

    ##DAY9 UITabBarController UIViewController的tabBarController UIViewController的tabBarItem #pragma mark ...