bzoj3620
2024-08-30 16:49:04
KMP
我似乎复杂度写的不对。。。
因为位置相同只算一次,后缀数组什么的都不管用了,我们就暴力kmp,但是我写的是暴力跳。。。竟然过了。。。我写bzoj3670才发现。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
int n, k, ans;
int nxt[N];
char s[N];
void kmp(char *s, int len, int *nxt)
{
for(int i = , j = ; i <= len; ++ i)
{
while(s[j + ] != s[i] && j) j = nxt[j];
if(s[j + ] == s[i]) ++ j;
nxt[i] = j;
}
}
int main()
{
scanf("%s%d", s + , &k);
n = strlen(s + );
for(int i = ; i <= n; ++i)
{
char t[N];
int len = ;
for(int j = i; j <= n; ++j) t[++ len] = s[j];
kmp(t, len, nxt);
for(int j = i; j <= n; ++j)
{
int p = j - i + ;
while(p * >= j - i + && p >= k) p = nxt[p];
if(p * < j - i + && p >= k) ++ ans;
}
}
printf("%d\n", ans);
return ;
}
最新文章
- jquery写的ajax
- 黄聪:使用srvany.exe将任何程序作为Windows服务运行
- pthread_cond_wait的原子性
- lumen 登陆 注册 demo
- centOS安装Mysql指南
- 已知ip地址和其子网掩码如何求网络号子网号主机号
- 【剑指offer】堆栈推弹出序列
- cocoapods管理以及常遇到的问题
- 网络流二十四题之P2764 最小路径覆盖问题
- layui layui.open弹窗后按enter键不停弹窗问题的解决
- ELK日志监控平台安装部署简介--Elasticsearch安装部署
- 缺省源和 Vim 配置
- servelet基础
- Ubuntu系统下安装免驱动摄像头
- Android系统更新防互刷功能实现与分析【转】
- 20155229《网络对抗技术》Exp5:MSF基础应用
- 【LeetCode OJ】Swap Nodes in Pairs
- css3整理--rgba
- runtime error (运行时错误)
- hdu 4686 Arc of Dream(矩阵快速幂)
热门文章
- poj 3683 2-sat问题,输出任意一组可行解
- spring几种依赖注入方式以及ref-local/bean,factory-bean,factory-method区别联系
- msp430项目编程23
- poj1376 bfs,机器人
- css三大特性
- [RxJS] `add` Inner Subscriptions to Outer Subscribers to `unsubscribe` in RxJS
- SDUTOJ 2475 Power Strings
- vue自定义轮播图组件 swiper
- 数据库分表和分库的原理及基于thinkPHP的实现方法
- Java设计模式-设计模式的六种原则