POJ 2406 Power Strings 简单KMP模板 strcmp
http://poj.org/problem?id=2406
只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了...
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const long long modn=;
char a[maxn]={};
int nex[maxn]={};
int n;
int doit(){
int j=-,i=;
nex[]=-;
while(i<n){
if(j==-||a[i]==a[j]){
nex[++i]=++j;
}else{
j=nex[j];
}
}
if(n%(n-nex[n])==){
return n/(n-nex[n]);
}
return ;
}
int main(){
while(~scanf("%s",a)){
memset(nex,,sizeof(nex));
if(strcmp(a,".")==){ break; }
n=strlen(a);
printf("%d\n",doit());
}
return ;
}
POJ 2406 Power Strings 简单KMP模板 strcmp的更多相关文章
- 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循环节)
题目链接:http://poj.org/problem?id=2406 题目大意:如果n%(n-next[n])==0,则存在重复连续子串,长度为n-next[n]. 例如: a b ...
- 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 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加深了理解 */ /************************************** ...
随机推荐
- sylk文件
症状:excel表出现提示:sylk文件...导致excel表不可读取 原因:文件内容有“ ID ” 字段,估计是固定的识别“ID”或“ID_XXXX” 修改方法:将ID中的任意字母换成小写即可 转载 ...
- NYOJ 163 Phone List (字符串处理 字典树)
题目链接 描述 Given a list of phone numbers, determine if it is consistent in the sense that no number is ...
- python3学习笔记.3.条件控制与循环
1.条件控制 关键字 if.elif.else 一般形式如下: if 条件1: 结果1 elif 条件2: 结果2 else: 结果3 注意:条件后的:语句的缩进的是相同的 2.循环语句 关键字有 ...
- 深入理解Spring之九:DispatcherServlet初始化源码分析
转载 https://mp.weixin.qq.com/s/UF9s52CBzEDmD0bwMfFw9A DispatcherServlet是SpringMVC的核心分发器,它实现了请求分发,是处理请 ...
- windows和linux修改python的pip源
python的pip安装包非常方便,然而其默认的镜像源在国外,下载的速度非常慢,推荐改成国内的镜像源. window平台修改pip源 找到系统盘下C:\C:\Users\用户名\AppData\Roa ...
- 新一代的USB 3.0传输规格
通用序列总线(USB) 从1996问世以来,一统个人电脑外部连接界面,且延伸至各式消费性产品,早已成为现代人生活的一部分.2000年发表的USB 2.0 High-speed规格,提供了480Mbps ...
- virsh 命令最新整理。 每个“;”之后是正解
1,migrate --domain --destURL --dname --live(热迁移) migrate lf 192.168.16.3 dname 2,managedsave domain ...
- acm专题---拓扑排序+优先队列
struct node{ int id; int cnt; node(int _id,int _cnt):id(_id),cnt(_cnt){} bool operator<(node a) c ...
- 详解Oracle的unlimited tablespace系统权限
1. 系统权限unlimited tablespace是隐含在dba, resource角色中的一个系统权限. 当用户得到dba或resource的角色时, unlimited tablespace系 ...
- 教你如何更改android应用的包名
Android 源码自带了很多应用程序,想改个包名方便修改?很简单,两步搞定,以packages/apps/Settings为例: 1.打开AndroidManifest.xml,把 <mani ...