题目大意:叙述的比较高大上,其实就是一个字符串B = AAAAAAA,求出来这个A最短有多长
 
分析:注意如果这个串不是完全循环的,那么循环节就是就是它本身。
 
代码如下:
#include<stdio.h>
#include<string.h> const int MAXN = 1e6+;
const int oo = 1e9+; char s[MAXN];
int next[MAXN]; void GetNext(int N)
{
int i=, j=-;
next[] = -; while(i < N)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
} int main()
{ while(scanf("%s", s), strcmp(s, "."))
{
int N = strlen(s); GetNext(N); int circle = N - next[N]; if(N % circle == )
printf("%d\n", N/circle);
else
printf("1\n");
} return ;
}

Power Strings - POJ 2406(求循环节)的更多相关文章

  1. Power Strings POJ - 2406

    Power Strings POJ - 2406 时限: 3000MS   内存: 65536KB   64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Gi ...

  2. ( KMP 求循环节的个数)Power Strings -- poj -- 2406

    链接: http://poj.org/problem?id=2406 Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bi ...

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

                                                                                                      Po ...

  4. Power Strings (poj 2406 KMP)

    Language: Default Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 33205   ...

  5. Power Strings POJ - 2406 后缀数组

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  6. Power Strings POJ - 2406(next水的一发 || 后缀数组)

    后缀数组专题的 emm.. 就next 循环节../ 有后缀数组也可以做 从小到大枚举长度i,如果长度i的子串刚好是重复了len/i次,应该满足len % i == 0和rank[0] - rank[ ...

  7. Match:Power Strings(POJ 2406)

     字符串前缀的阶 题目大意:求前缀的阶 和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的) #include <iostream> ...

  8. HDU 3746 Cyclic Nacklace (KMP求循环节问题)

    <题目链接> 题目大意: 给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数. [>>>kmp next函数 kmp的周期问题]  #include &l ...

  9. Java求循环节长度

    两个整数做除法,有时会产生循环小数,其循环部分称为:循环节.比如,11/13=6=>0.846153846153.....  其循环节为[846153] 共有6位.下面的方法,可以求出循环节的长 ...

随机推荐

  1. Difference Between XML and XAML.

    XML, or Extensible Markup Language, is a subset  of the more complex SGML (Standard Generalized Mark ...

  2. Qt经典出错信息之”Basic XLib functionality test failed!”

    解决方法: 此完整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the includ ...

  3. [LeetCode OJ] Gas Station

    问题描述: There are N gas stations along a circular route, where the amount of gas at station i is gas[i ...

  4. 【Ural1057】幂和的数量

    [题目描述] 写一个程序来计算区间[X,Y]内满足如下条件的整数个数:它恰好等于K个互不相等的B的整数幂之和. 举个例子.令X=15,Y=20,K=2,B=2.在这个例子中,区间[15,20]内有3个 ...

  5. 仿小米网jQuery全屏滚动插件fullPage.js

    演 示 下 载   简介 如今我们经常能见到全屏网站,尤其是国外网站.这些网站用几幅很大的图片或色块做背景,再添加一些简单的内容,显得格外的高端大气上档次.比如 iPhone 5C 的介绍页面,QQ浏 ...

  6. iOS 获取项目名称及版本号

    可用于版本让用户手动检测是否有版本更新可用. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  CFSho ...

  7. C /CLI思辨录[阅读记录]

    C /CLI思辨录之拷贝构造函数(避免多个实例在相同的堆对象的错误处理) http://west263.com/info/html/chengxusheji/C-C--/20080224/9247.h ...

  8. 基于BitNami for XAMPP进行Drupal7安装的教程(Win7平台)

    BitNami是一个开源项目,该项目产生的开源软件包可用于安装Web应用程序和解决方案堆栈,以及虚拟设备.BitNami 提供wordpress.joomla.drupal.bbpress等开源程序的 ...

  9. 谈谈android 布局 的优化

    来自:http://www.cnblogs.com/youxilua/archive/2012/05/08/2489414.html 导言 设配android的屏幕一定是一个噩梦,就好比那些搞网页设计 ...

  10. Java笔记原生数据类型【二】

    1.Java中的数据类型分为: 1)原生类型(primitive Data type) 2.)引用类型(对象类型) (Reference Type) 1.变量和常量: 常量: 就是值不会变化的量: 变 ...