题目大意:叙述的比较高大上,其实就是一个字符串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. oracle触发器调试

    1.如下图位置点击触发器,会出现调试窗口 2.执行编译并调试 3.点击小虫,将画红位置,加入会触发此触发器的语句.如果触发器执行成功,不会出现第4个图,不成功,会出现数据调试信息,具体报错位置会定位到 ...

  2. PictureBox内的图片拖动功能

    当 PictureBox内的图片太大,超过PictureBox边框时可以用下面的方法来实现,   通过重绘来实现 :   Code bool wselected = false;  Point p = ...

  3. 【POJ3468】【zkw线段树】A Simple Problem with Integers

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  4. mongo db安装和php,python插件安装

    安装mongodb 1.下载,解压mongodb(下载解压目录为/opt) 在/opt目录下执行命令 wget fastdl.mongodb.org/linux/mongodb-linux-x86_6 ...

  5. date日期比较和格式化方法

    时间的比较 var now = new Date();//现在时间 var setDate = new Date(2017,0,5,17,55,55);//设定的时间 laert(now < s ...

  6. mysql中显示方式的切换

    1. mysql中如果使用\G,则':'不用写.如果\G后面跟':'则会报"error:no query specified"错误.请知晓. 2. mysql在登陆时,mysql ...

  7. [r]Seven habits of effective text editing

    Seven habits of effective text editing(via) Bram Moolenaar November 2000 If you spend a lot of time ...

  8. Python - 多元组(tuple)

    声明一个多元组 (4, 5, 6) 这是列表 [4, 5, 6] 与列表不一样在于多元组使用() 来组织元素而list使用方括号[] 而且多元组不能更改,用于当你的数组不想像list一样会被更改时就使 ...

  9. SSI指令教程

    一:概述 SSI:服务器端嵌入或者叫服务器端包含,是Server Side Include的简写.SSI技术通过在文档中加入SSI指令,让服务器端在输出文档之前解析SSI指令,并把解析完的结果和文档一 ...

  10. 将数据库字段从float修改为decimal

    decimal(6,2) 可以表示0000.00~9999.99 alter table test modify aaa decimal(6,2); 则表里所有大于10000的数会被设置为9999.9 ...