字符串前缀的阶

  题目大意:求前缀的阶

  和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. fatal: Paths with -a does not make sense.

    git commit -am '*屏蔽设置缓存' htdocs/s.php fatal: Paths with -a does not make sense. 应该用下面的这样. git commit ...

  2. 你真的懂了R中的stem函数是如何绘制茎叶图的么?

    本文原创,转载请注明出处,本人Q1273314690(交流学习)   哭晕 你真的学会了stem()函数了吗? stem()函数的使用方法是: stem(x, scale=1,width=80, at ...

  3. IOS开发之----NSDictionary,JSON和XML互相转换

    本文永久地址为 http://www.cnblogs.com/ChenYilong/p/4044521.html,转载请注明出处.     -(void)test {     //XML文本范例   ...

  4. 分分钟教会大家第一个Spring入门案例

    1.下载Spring jar包,并添加到项目中. 官网地址http:springsource.org 2.在项目中新建一个类      package cn.test; public class He ...

  5. 怎么看网站是否开启CDN加速?测试网站全国访问速度方法详解

    注意域名,动静分离的网站,只对静态文件的域名做了cdn 怎么看网站有没开启CDN? 要看一个网站是否开启CDN,方法很简单,只要在不同的地区ping网址就可以,比如在山东济南ping www.jb51 ...

  6. Windows下MySQL 5.6安装及配置详细图解

    一.安装前的准备 1.下载安装程序包,可到MySQL官方网站http://www.mysql.com/下载,如图1-1: 图1-1 下载后的安装文件如图1-2所示: 图1-2 二.安装 1.双击下载的 ...

  7. PL/SQL创建数据表空间

    创建数据表空间create tablespace stbss datafile 'E:\oracle\product\10.2.0\oradata\orcl\stbss_temp01.dbf' siz ...

  8. 实现Android的不同精度的定位(基于网络和GPS)

    解决方案: 实现Android的不同精度的定位(基于网络和GPS) Android中的定位服务的相关类基本上都在android.location包中,其中位置服务管理器(LocationManager ...

  9. Java中Runnable和Thread

    java中有两种实现多线程的方式:一种是继承Thread类,一种是实现Runnable接口. 1.java启动线程为什么使用start函数呢? 在JDK的安装路径下,src.zip是全部的java源程 ...

  10. Codeforces 271 Div 2 B. Worms

    题目链接:http://codeforces.com/contest/474/problem/B 解题报告:给你n个堆,第i个堆有ai个物品,物品的编号从1开始,第一堆的编号从1到a1,第二堆编号从a ...