前缀数组O(n^3)做法

s.substr()的应用非常方便

令string s = "";

string sub1 = s.substr(); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = "56789"

string sub2 = s.substr(, ); //从下标为5开始截取长度为3位:sub2 = "567"
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#pragma GCC optimize(2)
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 1000010
#define For(i,a,b) for(int i=a;i<=b;++i)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int len;
string s;
int ans[N];
void in(int &x){
int y=;char c=g();x=;
while(c<''||c>''){if(c=='-')y=-;c=g();}
while(c<=''&&c>=''){ x=(x<<)+(x<<)+c-'';c=g();}
x*=y;
}
void o(int x){
if(x<){p('-');x=-x;}
if(x>)o(x/);
p(x%+'');
} int main(){
cin>>s;
len=s.size();
For(i,,len-)
For(k,,i)
if(s.substr(,k)==s.substr(i-k+,k))
ans[i]=k;
For(i,,len-)
o(ans[i]),p(' ');
return ;
}

前缀数组O(n^3)做法的更多相关文章

  1. 转载-KMP算法前缀数组优雅实现

    转自:http://www.cnblogs.com/10jschen/archive/2012/08/21/2648451.html 我们在一个母字符串中查找一个子字符串有很多方法.KMP是一种最常见 ...

  2. codeforces 381 D Alyona and a tree(倍增)(前缀数组)

    Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. poj 2046&&poj1961KMP 前缀数组

    Power Strings Time Limit: 3000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Jav ...

  4. 子串查询(二维前缀数组) 2018"百度之星"程序设计大赛 - 资格赛

    子串查询 Time Limit: 3500/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Subm ...

  5. 线段树、前缀数组:HDU1591-Color the ball(区间更新、简单题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. POJ-2752(KMP算法+前缀数组的应用)

    Seek the Name, Seek the Fame POJ-2752 本题使用的算法还是KMP 最主要的片段就是前缀数组pi的理解,这里要求解的纸盒pi[n-1]有关,但是还是需要使用一个循环来 ...

  7. JS判断是否是数组的四种做法

    一.前言 如何判断一个对象或一个值是否是一个数组,在面试或工作中我们常常会遇到这个问题,既然出现频率高,想着还是做个整理,那么本文主要基于几种判断方式,以及方式判断的原理,是否存在问题展开讨论. 二. ...

  8. JS判断是否是数组的四种做法(转载)

    转载来源 https://www.cnblogs.com/echolun/p/10287616.html 一.前言 如何判断一个对象或一个值是否是一个数组,在面试或工作中我们常常会遇到这个问题,既然出 ...

  9. hdu3336 KMP + DP 前缀数组出现的次数

    题意:       给你一个串,问你他的所有前缀子串在本串中的出现次数,注释:abc的前缀子串是 a ab abc; 思路:      还是利用了next数组,先对子串求出next数组,再开一个数组d ...

随机推荐

  1. Java集合框架(List,Set,Map)

    单列集合基本框架 List接口特点:1. 它是一个元素存取有序的集合.例如,存元素的顺序是11.22.33.那么集合中,元素的存储就是按照11.22.33的顺序完成的). 2. 它是一个带有索引的集合 ...

  2. day34 异常处理、断言、socket之ftp协议

    Python之路,Day20 = 异常处理.断言.socket之ftp协议 参考博客:http://www.cnblogs.com/metianzing/articles/7148191.html 异 ...

  3. spring boot项目开发中遇到问题,持续更新

    1.JPA中EntityManager不能执行建表语句,提示要加事务Error:javax.persistence.TransactionRequiredException: Executing an ...

  4. 同一个tomcat 两个项目 互相访问接口方法

    package com.qif.xdqdm.util; import com.alibaba.fastjson.JSONObject; import java.io.*; import java.ne ...

  5. idea运行tomcat,控制台中文乱码

    加入参数:-Dfile.encoding=UTF-8

  6. Assert(断言) 的用法

    Assert Assert是断言的意思,头文件为assert.h, assert是一个宏 功 能: 测试一个条件并可能使程序终止 用 法: void assert(int test); 在单元测试中经 ...

  7. UVA-108-Maximum Sum-子矩阵最大和(最大连续子序列的变形)+降维处理+dp

    A problem that is simple to solve in one dimension is often much more difficult to solve in more tha ...

  8. day 82 Vue学习三之vue组件

      Vue学习三之vue组件   本节目录 一 什么是组件 二 v-model双向数据绑定 三 组件基础 四 父子组件传值 五 平行组件传值 六 xxx 七 xxx 八 xxx 一 什么是组件 首先给 ...

  9. PAT甲级——A1114 Family Property【25】

    This time, you are supposed to help us collect the data for family-owned property. Given each person ...

  10. 石子合并问题 /// 区间DP oj2025

    Description 在一个圆形操场的四周摆放着n堆石子.现要将石子有次序地合并成一堆. 规定每次只能选相邻的两堆石子合并成新的一堆,并将新得的这堆石子数记为该次合并的得分. 试设计一个算法,计算出 ...