(简单) POJ 2406 Power Strings,扩展KMP。
Description
水题,扩展KMP。
代码如下:
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月18日 星期六 10时54分33秒
// File Name : 2406.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; void EKMP_pre(int m,char s[],int next1[])
{
int p=,a=,L; next1[]=m; while(p+<m && s[p]==s[p+])
++p; next1[]=p; for(int k=;k<m;++k)
{
L=next1[k-a];
p=next1[a]+a-(next1[a]!=); if(k+L-<p)
next1[k]=L;
else
{
++p; while(p<m && s[p]==s[p-k])
++p; next1[k]=p-k;
a=k;
}
} next1[m]=;
} int N;
char s[MaxN];
int next1[MaxN]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(~scanf("%s",s))
{
if(s[]=='.' && s[]==)
break; N=strlen(s); EKMP_pre(N,s,next1); int i; for(i=;i<N;++i)
if(next1[i]+i==N && next1[i]%i==)
break; printf("%d\n",N/i);
} return ;
}
(简单) POJ 2406 Power Strings,扩展KMP。的更多相关文章
- poj 2406:Power Strings(KMP算法,next[]数组的理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30069 Accepted: 12553 D ...
- poj 2406 Power Strings(KMP入门,next函数理解)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 37685 Accepted: 15590 D ...
- poj 2406 Power Strings(kmp应用)
题目链接:http://poj.org/problem?id=2406 题意:给出一个字符串s,求重复子串出现的最大次数. 分析:kmp的next[]数组的应用. 要求重复子串出现的最大次数,其实就是 ...
- POJ 2406 Power Strings(KMP)
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- poj 2406 Power Strings(kmp循环节)
题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如: a b ...
- poj 2406 Power Strings(kmp next的应用)
题目链接:http://poj.org/problem?id=2406 题意:就是求一个字符串最多有几个相同的小字符串组成. 题解:直接求一下next然后找到长度,长度就是len-1-next[len ...
- poj 2406 Power Strings(kmp求一个串的重复子串)
题意:重复子串次数 思路:kmp #include<iostream> #include<stdio.h> #include<string.h> using nam ...
- poj 2406 Power Strings【kmp】
kmp,根据next数组的性质如果有答案的话就是n/(n-(ne[n]+1)),否则是1 搬来打算用SA后来发现必须用DC3就没写 #include<iostream> #include& ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
随机推荐
- 【最长下降子序列的长度和个数】 poj 1952
转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...
- Video Cards
Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- WPF Template模版之寻找失落的控件【三】
“井水不犯河水”常用来形容两个组织之间界限分明.互不相干,LogicTree与控件内部这颗小树之间就保持着这种关系.换句话说,如果UI元素树上有个X:Name=“TextBox1”的控件,某个控件内部 ...
- json的学习笔记
json比较简单,所以先从json开始学起. 一 json的名称: json的全称是javascript object notation,中文名称为js 对象表示法. json的定义:json是一种轻 ...
- Swift -> Optional嵌套 探讨
准备运动:Optional 的介绍 王巍的<Swifter>一书中,介绍了一个有用的命令:在 LLDB 中输入 fr v -R foo,可以查看foo 这个变量的内存构成.我们稍后的分析将 ...
- tomcat内存优化问题
Java内存组成 1) 堆 运行时数据区域,所有类实例和数组的内存均从此处分配.Java 虚拟机启动时创建.对象的堆内存由称为垃圾回收器 的自动内存管理系统回收. 堆由两部分组成: 其中eden+fr ...
- ubuntu下安装多个jdk的切换命令update-alternatives
update-alternatives 以前叫alternatives 下面的介绍,直接引用了,其中必须安装了才会在候选里面出现. usage: update-alternatives --inst ...
- 使用Qt报错error while building deploying project
方法一:点击左侧的“项目”栏,看“构建目录”栏的路径,一定要注意,在路径中一定不要出现汉字,否则一定会报“error while building deploying project”的错误. 方法二 ...
- JSP 语法/标签
┣1.declaration Declaration定义了JSP脚本语言使用的变量和函数,这类似于Java中定义全局变量,或可以把它想像成pascal编程语言中的单元文件的interface部分.声明 ...
- Ubuntu 9.10+ apache2.2 +Django的配置
1.首先安装mod_python apt-get install libapache2-mod-python2.6 (Ubuntu 9.10默认安装的是python 2.6版,如果是2.5可改为 li ...