字符串前缀的阶

  题目大意:求前缀的阶

  和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的)

  

 #include <iostream>
#include <algorithm>
#include <functional>
#include <string.h> using namespace std; static char Text[];
static int _Next[]; void Input(int &);
void Get_Next(const int); int main(void)
{
int Length, k_count, if_res;
while ()
{
Input(Length);
if (*Text == '.')//小数点结束
break;
Get_Next(Length);
if_res = Length % (Length - _Next[Length]);
k_count = Length / (Length - _Next[Length]);
if (if_res == && k_count > )
printf("%d\n", k_count);
else printf("1\n");
}
return EXIT_SUCCESS;
} void Input(int &Length)
{
Length = ;
scanf("%s", Text);
Length = strlen(Text);
} void Get_Next(const int Length)
{
int i = , k = -;
_Next[] = -; while (i < Length)
{
if (k == - || Text[i] == Text[k])
{
i++;
k++;
_Next[i] = k;
}
else k = _Next[k];
}
}

  

  另外以这一题有散列做法,但是没有kmp那么快,但是用到了一个非常好的算法——矩阵快速幂,以后补

Match: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. Power Strings (poj 2406 KMP)

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

  4. Power Strings POJ - 2406 后缀数组

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

  5. Power Strings - POJ 2406(求循环节)

    题目大意:叙述的比较高大上,其实就是一个字符串B = AAAAAAA,求出来这个A最短有多长   分析:注意如果这个串不是完全循环的,那么循环节就是就是它本身.   代码如下: #include< ...

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

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

  7. 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中的出现位置或者是次数 这个出现的次数是可 ...

  8. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

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

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

随机推荐

  1. Linux 运行 apt-get install 就出现jdk installer 错误的解决方法

    解决办法如下: sudo rm /var/lib/dpkg/info/oracle-java7-installer* sudo apt-get purge oracle-java7-installer ...

  2. java.lang.Class

    java.lang.Class 一.Class类是什么 Class是一个类,位于java.lang包下. 在Java中每个类都有一个相对应的Class类的对象,换句话说:Java程序在启动运行时 一个 ...

  3. 响应性web设计实战总结(二)

    响应性web设计实战总结(二) 阅读目录 背景知识: Gulp-less安装及配置如下 对响应性web总结,之前总结过2篇文章:可以看如下: http://www.cnblogs.com/tugenh ...

  4. [译]git reflog

    用法 git reflog 显示整个本地仓储的commit, 包括所有branch的commit, 甚至包括已经撤销的commit, 只要HEAD发生了变化, 就会在reflog里面看得到. git ...

  5. EF-error 0152: No Entity Framework provider found...

    突然就报这个错了... ... 哈哈··· 原来是 "EntityFramework.SqlServer.dll" 没有引用··· 添加引用就好了... ... 还好不了?那就不知 ...

  6. nyoj 252 01串 动态规划( java)

    当n=2时, 输出 3:当n=3时, 输出 5:当n=4时, 输出 8: #### 分析: 当n=4时,如 0101 符合条件, 当第一个位置是0时,还剩3个位置 ,与n=3时个数相等: 符合条件的为 ...

  7. JSON 问题

    {"statusCode":"300","message":"栏目插入出现故障==bannerInfoService.add 栏目 ...

  8. cocos2d-x内存管理(见解)

    cocos2d-x 延续了cocos2d 和OC的引用计数的内存管理机制! 下面我们来看看CCDriectro类 CCPoolManager::sharedPoolManager()->push ...

  9. javascript高级程序设计---Event对象三

    进度事件 进度事件用来描述一个事件进展的过程,比如XMLHttpRequest对象发出的HTTP请求的过程.<img>.<audio>.<video>.<st ...

  10. phpMyAdmin 缺少 mysqli 扩展。请检查 PHP 配置

    好久没有在windows下配置php了,今天,按照前一篇文章配置好,打开phpmyadmin时,出现如下问题: phpMyAdmin 缺少 mysqli 扩展.请检查 PHP 配置 网上搜索解决方案, ...