POJ-2406(KMP+字符串压缩)
Power String
POJ-2406
字符串压缩模板题,但是是求有多少个这样最短的子串可以组成s。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
const int N=10000001;
int pi[N];
void Pi(string s){
memset(pi,0,sizeof(pi));
int n=s.length();
pi[0]=0;
for(int i=1;i<n;i++){
int j=pi[i-1];
while(j>0&&s[i]!=s[j]){
j=pi[j-1];
}
if(s[i]==s[j])
j++;
pi[i]=j;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
string s;
while(cin>>s){
if(s==".")
break;
Pi(s);
int n=s.length();
int k=n-pi[n-1];
if(n%k==0&&pi[n-1]>0){
cout<<n/k<<endl;
}else
{
cout<<1<<endl;
}
}
return 0;
}
POJ-2406(KMP+字符串压缩)的更多相关文章
- POJ 2406 KMP/后缀数组
题目链接:http://poj.org/problem?id=2406 题意:给定一个字符串,求由一个子串循环n次后可得到原串,输出n[即输出字符串的最大循环次数] 思路一:KMP求最小循环机,然后就 ...
- Power Strings (poj 2406 KMP)
Language: Default Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 33205 ...
- poj(2406) kmp
题目链接:https://vjudge.net/problem/POJ-2406 kmp学习:https://blog.csdn.net/starstar1992/article/details/54 ...
- POJ 2406 KMP 循环节
给一个字符串.求这个串的最小的循环节的长度. 好像.num = len/(len-next[len]) 就是循环节的长度.如果 len%(len-next[len]) ==0 就是 说字符串长度刚好是 ...
- POJ 2406 KMP next数组的应用
题意:让你找最小重复串的个数 加深KMP中对next数组的理解 #include <cstdio> #include <cstring> using namespace std ...
- poj 2406 求字符串中重复子串的个数
Sample Input abcdaaaaababab.Sample Output 1 //1个abcd4 //4个a3 //3个ab #include<stdio.h> #include ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
- HDOJ-1358(字符串压缩+KMP)
Period HDOJ-1358 这题还是属于KMP算法的应用,属于字符串压缩问题.也就是在一个字符串s中寻找一个前缀,使得s可以被一份或者多份前缀子串t拷贝连接,也就是串接. #include< ...
- Power Strings POJ - 2406
Power Strings POJ - 2406 时限: 3000MS 内存: 65536KB 64位IO格式: %I64d & %I64u 提交 状态 已开启划词翻译 问题描述 Gi ...
随机推荐
- OpenStack Train版-7.neutron网络服务概述
网络服务NEUTRON概述 一.NEUTRON架构 OpenStack的网络服务neutron是整个OpenStack中最复杂的一个部分,它的基本架构是一个中心服务(neutron-server)外加 ...
- HDU - 4455 Substrings(非原创)
XXX has an array of length n. XXX wants to know that, for a given w, what is the sum of the distinct ...
- 关于free和delete的使用
上一篇篇幅太长,这里再区分free和delete的用法. 两个同时存在是有它的原因的,我们前面说过,free是函数,它只释放内存,但不会调用析构函数,如果用free去释放new申请的空间,会因为无法调 ...
- 关于malloc/free用法
和很多人一样,我一直觉得new/delete和malloc/free的用法很随意,直到我真正遇到了麻烦,才想着去好好区分一下. (1)首先mallo函数原型void* malloc(size_t).头 ...
- IT-ebooks free download website & IT 电子书籍免费下载网站
free ebooks of programming 1. http://www.it-ebooks.info/ http://www.it-ebooks-api.info/ 2. http://ww ...
- node.js 怎么扩大默认的分配的最大运行内存
node.js 怎么扩大默认的分配的最大运行内存 $ node --max-old-space-size=4096 app.js $ NODE_OPTIONS=--max-old-space-size ...
- window.navigator All In One
window.navigator All In One navigator "use strict"; /** * * @author xgqfrms * @license MIT ...
- js swap array
js swap array ES6 swap array 就地交换 no need let , const [ b, a, ] = [ a, b, ]; // ES6 swap const arr = ...
- React Hooks & React v16.8.6
React Hooks Hooks are a new addition in React 16.8 const [state, setState] = useState(initialState); ...
- py 时间处理
字符串解析 如果你使用的不是isoformat string那么解析字符串就会失败,需要用strptime转换一下 import datetime datetime.datetime.strptime ...