前缀数组O(n^3)做法
前缀数组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)做法的更多相关文章
- 转载-KMP算法前缀数组优雅实现
转自:http://www.cnblogs.com/10jschen/archive/2012/08/21/2648451.html 我们在一个母字符串中查找一个子字符串有很多方法.KMP是一种最常见 ...
- 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 ...
- poj 2046&&poj1961KMP 前缀数组
Power Strings Time Limit: 3000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Jav ...
- 子串查询(二维前缀数组) 2018"百度之星"程序设计大赛 - 资格赛
子串查询 Time Limit: 3500/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- 线段树、前缀数组:HDU1591-Color the ball(区间更新、简单题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- POJ-2752(KMP算法+前缀数组的应用)
Seek the Name, Seek the Fame POJ-2752 本题使用的算法还是KMP 最主要的片段就是前缀数组pi的理解,这里要求解的纸盒pi[n-1]有关,但是还是需要使用一个循环来 ...
- JS判断是否是数组的四种做法
一.前言 如何判断一个对象或一个值是否是一个数组,在面试或工作中我们常常会遇到这个问题,既然出现频率高,想着还是做个整理,那么本文主要基于几种判断方式,以及方式判断的原理,是否存在问题展开讨论. 二. ...
- JS判断是否是数组的四种做法(转载)
转载来源 https://www.cnblogs.com/echolun/p/10287616.html 一.前言 如何判断一个对象或一个值是否是一个数组,在面试或工作中我们常常会遇到这个问题,既然出 ...
- hdu3336 KMP + DP 前缀数组出现的次数
题意: 给你一个串,问你他的所有前缀子串在本串中的出现次数,注释:abc的前缀子串是 a ab abc; 思路: 还是利用了next数组,先对子串求出next数组,再开一个数组d ...
随机推荐
- System.DateTime.cs
ylbtech-System.DateTime.cs 1. 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...
- Sequelize
连接数据库 const DB = require('sequelize') // 连接数据库 const connect = new DB('xjg', 'root', 'root', { host: ...
- 20.multi_case06
# coding:utf-8 import asyncio # 通过create_task()方法 async def a(t): print('-->', t) await asyncio.s ...
- neo4j算法(1)-介绍
neo4j为图数据库,其中涉及的也就为图算法,图算法被用来度量图形,节点及关系. 在neo4j中,通过call algo.list() 可查看neo4j中的算法列表. 在neo4j官方文档中,主要记录 ...
- 语音识别(语音转文字)&& 语音合成(文字转语音)
[语音合成API]SpeechSynthesisUtterance是HTML5中新增的API,用于将指定文字合成为对应的语音.也包含一些配置项,指定如何去阅读(语言,音量,音调)等 // 语音播报 s ...
- Slim模型部署多GPU
1 多GPU原理 单GPU时,思路很简单,前向.后向都在一个GPU上进行,模型参数更新时只涉及一个GPU. 多GPU时,有模型并行和数据并行两种情况. 模型并行指模型的不同部分在不同GPU上运行. 数 ...
- SPOJ10707 COT2-Count on a tree II
COT2 - Count on a tree II 中文题意 离线询问一颗树上路径(u,v)中经过所有点的权值的种类数. 题解 树上莫队.即在树的欧拉序列上进行莫队.同一个点加第一次时增加,第二次时减 ...
- selenium学习笔记——driver.get(url) 页面加载时间太长
# 两个同时设置才行 # 实现效果:加载状态停止,进行代码下一步操作 driver.set_page_load_timeout(10) driver.set_script_timeout(10) # ...
- Making the Grade
Making the Grade 给定长度为n的序列\(\{a_i\}\),求构造长度为n的递增序列\(\{b_i\}\),求\(\sum_{i=1}^n|a_i-b_i|\)最小值,\(1 ≤ N ...
- sql中on的连接条件与where的区别
left join [表名] on [条件] where [条件] --on表示连接条件 --where表示对结果的过滤条件 两者不尽相同,使用时需注意 例如: select * from tabl ...