(简单) 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加深了理解 */ /************************************** ...
随机推荐
- Server的Transfer和Response的Redirect
在实现页面跳转的时候,有些人喜欢用Response.Redirect,而有些人则喜欢用Server.Transfer.大部分时间似乎这两种方法都可以实现相同的功能,那究竟有区别吗? 查了些文档,发现两 ...
- ASP.NET中使用Server.Transfer()方法在页间传值 实例
以下代码在VS2008中测试通过 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...
- FileSystemXmlApplicationContext方法的绝对路径问题
public AgentServer(Socket c,String confDir) { this.client = c; ApplicationContext ac = new FileSyste ...
- Android Studio中配置及使用OpenCV示例
Android Studio配置及使用OpenCV 前言:最近在做项目移植,项目较大,在Eclipse中配置的Jni及OpenCV环境没任何问题,但是迁移到Studio中就问题一大堆,网上也找了一些资 ...
- [转]探究java IO之FileInputStream类
使用FileInputStream类创建的InputStream对象可以用于从文件读取内容.两个常用的构造函数如下所示: ? 1 2 FileInputStream(String filePath) ...
- POJ 2186 Popular Cows tarjan缩点算法
题意:给出一个有向图代表牛和牛喜欢的关系,且喜欢关系具有传递性,求出能被所有牛喜欢的牛的总数(除了它自己以外的牛,或者它很自恋). 思路:这个的难处在于这是一个有环的图,对此我们可以使用tarjan算 ...
- Box2d b2World的RayCast方法
RayCast方法: world.RayCast(callback:Function,point1:b2Vec2,point2:b2Vec2); * callback 回调函数 * point1 射线 ...
- C#无边框窗体移动 将事件绑定到想实现的控件上
[DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("use ...
- DevExpress.LookUpEdit控件实现自动搜索定位功能 兼使用方法(looUpEdit可编辑)
DevExpress.LookUpEdit 使用方法 设置可手动输入 this.LookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditor ...
- Android消息提示框Toast
Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...