hdu-1686-Oulipo(KMP)

Allegro模块复用:从原理图到PCB的完整流程与关键细节 本文详细介绍了Allegro模块复用从原理图到PCB的完整流程与关键细节,包括DSN和MDD文件的创建、模块调用的实战技巧以及双向同步与版本控制方法。通过标准化处理和高级复用技巧,能显著提升PCB设计效率,减少重复工作时间。适用于智能硬件和工业控制等领域的工程师。 阅读详情

Oulipo

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16577    Accepted Submission(s): 6640


Problem Description
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:

Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, puis surgissait l’inhumain, l’affolant. Il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : stir son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…

Perec would probably have scored high (or rather, low) in the following contest. People are asked to write a perhaps even meaningful text on some subject with as few occurrences of a given “word” as possible. Our task is to provide the jury with a program that counts these occurrences, in order to obtain a ranking of the competitors. These competitors often write very long texts with nonsense meaning; a sequence of 500,000 consecutive 'T's is not unusual. And they never use spaces.

So we want to quickly find out how often a word, i.e., a given string, occurs in a text. More formally: given the alphabet {'A', 'B', 'C', …, 'Z'} and two finite strings over that alphabet, a word W and a text T, count the number of occurrences of W in T. All the consecutive characters of W must exactly match consecutive characters of T. Occurrences may overlap.

 

Input
The first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

One line with the word W, a string over {'A', 'B', 'C', …, 'Z'}, with 1 ≤ |W| ≤ 10,000 (here |W| denotes the length of the string W).
One line with the text T, a string over {'A', 'B', 'C', …, 'Z'}, with |W| ≤ |T| ≤ 1,000,000.
 

Output
For every test case in the input file, the output should contain a single number, on a single line: the number of occurrences of the word W in the text T.

 

Sample Input
3 BAPC BAPC AZA AZAZAZA VERDI AVERDXIVYERDIAN
 

Sample Output
1 3 0
 
题意:看样例都能看懂
KMP模板
code:
#include<cstdio>
#include<cstring>
#define MAXN 1000010
#define LEN 1000010
using namespace std;
int next[MAXN];
char a[MAXN],b[LEN];
int n,m;
void get_next()
{
    int k=-1,j=0;
    next[0]=-1;
    while(j<m){
        if(k==-1||a[j]==a[k]){
            k++;j++;
            next[j]=k;
        }else
            k=next[k];
    }
}
int kmp()
{
    int ans=0,i=0,j=0;
    while(i<n){
        if(j==-1||a[j]==b[i]){
            i++;j++;
        }else
            j=next[j];
        if(j==m){
            ans++;
            j=next[j];
        }
    }
    return ans;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s%s",a,b);
        n = strlen(b);
        m = strlen(a);
        get_next();
        printf("%d\n",kmp());
    }
    return 0;
}


用Matlab系统辨识工具箱搞定温控系统建模:从阶跃响应到传递函数(附完整代码) 本文详细介绍了如何使用Matlab系统辨识工具箱进行温控系统建模,从阶跃响应数据采集到传递函数参数辨识的全过程。通过实际案例和完整代码,帮助工程师快速掌握PID控制参数整定技巧,提升温控系统设计效率。特别适合单片机开发者和自动化控制工程师参考。 阅读详情

相关推荐

Matlab使用GitHub的踩坑记录(持续更新)

Matlab使用git的踩坑记录前言Matlab设置Git的官方帮助文档系统配置新建Git两种代码管理方式典型源代码管理SVN分布式源代码管理 Git注意:SVN和Git都可以用GitHub创建新的库 前言 作为Git初学者,对Git的代码版本管理非常非常喜欢,给了我极大的安全感。特别是想到之前的几次Matlab、Latex和python的代码莫名其妙被折腾没了又没法找回的悲剧,决定慢慢的走入gi...

voluntry的博客 7304

HDU 1686(Oulipo)

题意:给定文本串 a 和 模式串 b ,求 b 在 a 中出现过多少次。 分析:KMP裸题,稍微改动一下就可以 了 代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; const int N = 1E6+10; const int M...

Joker & Liar的博客 210

Pseudobulk与FindMarkers单细胞差异基因分析实战对比

本文深入对比了单细胞差异基因分析中Pseudobulk与FindMarkers两种主流方法。通过实战演示,详细解析了二者在底层逻辑、数据准备、分析流程及结果解读上的核心差异,并提供了基于不同生物学问题与数据特点的选择策略,帮助研究者做出更精准的分析决策。

weixin_29218963的博客 342

HDU-1686 Oulipo

传送门 t组数据 求模式串在文本串中的出现次数(允许重叠) 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 typedef long long LL; 6 7 const int max...

weixin_33769125的博客 124

『n8n』初识界面

在首页(Overview),我们和 n8n 最常打交道的是“Workflows”、“Credentials”、“Executions”这几个面板(其实后面2个也会用到,但初学阶段可以先不管)。Workflows 面板可以看到我们创建的所有工作流,所以要给工作流起一个一眼看上去就知道是干嘛的名字。

weixin_39415598的博客 1471

adas硬件_ADAS智能辅助驾驶系统硬件在环(HIL)测试之硬件介绍

这篇主要分享的是ADAS融合系统的HIL测试系统的硬件结构及其作用,其主要包括上位机、机柜、雷达模拟器系统、雷达暗箱系统以及视频暗箱。 上位机 上位机主要运行HIL测试系统的相关软件,测试人员所有的前期准备工作与测试操作均在上面进行,并监控测试结果,其通过网口实现与NI实时机的通信,上位机将VeriStand项目工程下载至NI实时机运行。机柜 机柜主要由可编程电源...

weixin_39580748的博客 2258

hdu(1686)——Oulipo

题意: 给你两个串A,B,让你求A串在B串中的出现次数。 思路: kmp。。。但是一开始没想通,其实只要在求next数组时,最后把len-1那个位置的next值也求出来就好了,因为我们知道了最后一个字母对应的最大公共前缀后缀,那么我们就可以在第二个样例的时候当完成第一次匹配后,我们知道文本串后一位应该和模式串的那一位去匹配了。其实说白了就是把最后一个字母的最大公共前缀后缀也求出来了嘛,这样我

ACM_hades的梦想之路 1606

切比雪夫(最小区域法)直线拟合算法

切比雪夫,最小区域法直线拟合

闪电彬彬的博客 3986

Hdu 1686 Oulipo(KMP入门)

传送门 题意:给你一个长度为W的模式串(1 ≤ |W| ≤ 10,000)和一个长度为T的文本串(|W| ≤ |T| ≤ 1,000,000),问你这个模式串在文本串中出现了几次,注意样例里面的这一组样例AZA AZAZAZA 输出的是3而不是2,重复的也算一次。 分析:显然根据HDU一贯的作风(套路),这题我们肯定不能用朴素的暴力匹配,那样的话,复杂度是O(M*N),肯定会超时,其实这题就是...

不期而遇 226

告别Modern Standby!Win10/11强制S3睡眠的终极指南(含BIOS设置避坑)

本文是针对Windows 10/11用户因Modern Standby(S0低电量待机)导致睡眠耗电、发热问题的终极解决方案。文章详细对比了Modern Standby与传统S3睡眠(Suspend to RAM)的本质区别,并提供了从系统诊断、注册表修改、BIOS/UEFI设置避坑到驱动优化的完整步骤,旨在帮助用户强制启用稳定、省电的S3睡眠模式,彻底告别睡眠噩梦。

n7o8p的博客 834

机器人控制基础:电机编码器常见类型

电机编码器是测量电机位置、速度和方向的传感器,主要分为光电、磁性和旋转变压器三类。光电编码器精度高但需防尘,适用于伺服系统;磁性编码器耐环境性强,常用于汽车电机;旋转变压器适应极端环境,多用于军工领域。按信号类型可分为增量式(成本低)和绝对式(断电保留位置)。选型需综合考虑精度、环境适应性及成本。

start_up_go的博客 482

hdu1686

http://acm.hdu.edu.cn/showproblem.php?pid=1686 #include #include #include using namespace std; char w[15000]; char t[1000005]; int next[15000]; void get_next() { int l=strlen(w); int i,j;

skyline 1477

倍福--RS232自由口实现

RS232/485通信协议是在现场中常用到的,比如触摸屏、温控模块等设备控控制器做通信,会常用到此类协议,本文介绍RS232/485自由口通信的实现,并用PC调试助手进行测试。 目 录 软硬件版本 3 1.1. 倍福Beckhoff 3 1.1.1. 控制器硬件 3 1.1.2. 控制器软件 3 硬件连接 3 2.1. PC COM介绍 3 2.2. RS232/RS485连接 3 3.2.1. N030…………. 4 3.2.2. N031…………. 4 2.3. 实际线路连接 5 PLC程序 7 3

weixin_41883890的博客 3291

hdu 1686 Oulipo(KMP)

题目链接:hdu 1686 Oulipo 题目大意:给出两个字符串W, T,问说T字符串中有几个子串和W字符串匹配。 解题思路:KMP,只不过在找到匹配串的时候不能直接跳出或者说让p=0,应该让p = next[p]。 #include #include const int N = 1000005; const int M = 10005; int n,

不慌不忙、不急不躁 912

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

HDU-1686- Oulipo KMP匹配

POJ-3461 Oulipo PJ的女朋友是一个书法家,喜欢写一些好看的英文书法。有一天PJ拿到了她写的纸条,暗示要送给他生日礼物。PJ想知道自己想要的礼物是不是就是她送的,于是想看看自己想要的在纸条中出现了多少次。 Input 第一行输入一个整数代表数据的组数 每组数据第一行一个字符串 W代表PJ想要的礼物, 包含英语字符 {‘A’, ‘B’, ‘C’, …, ...

Anoyer的博客 424

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

【kmp字符串匹配】hdu 1686 Oulipo

hdu 1686 Oulipohttp://acm.hdu.edu.cn/showproblem.php?pid=1686问题描述:字符串匹配次数暴力复杂度O(n×m),无谓的比较过多;kmp算法能优化到O(n+m),直接套板思路kmp_count()返回匹配成功的次数参考代码 #include<iostream> #include<cstdio> #include<cstdlib> #includ

Hacker_vision 478

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDU - 1686 Oulipo(KMP模板题)

HDU - 1686 Oulipo #include<cstdio> #include<cstring> char a[10010],b[1000010]; int p[10010]; int n,m,c; void getnext() { int i=0,j=-1; memset(p,-1,sizeof p); while(i<n) { if(j==-1||a[i]==a[j]) p[++i]=++j; else j=p[j]; } } void kmp

00后的博客 280

【KMP】HDU 1686 Oulipo

哈希和KMP两种解法。颜文字缺失qwq

L_X_ 240

HDU 1686 Oulipo(KMP)

题目链接:点击打开链接 KMP超级水的模板题...... // HDU 1686 Oulipo.cpp 运行/限制:124ms/1000ms #include #include #include using namespace std; char w[10005], t[1000005]; int Next[10005]; void MP() { int n = strlen(w);

不忘初心 490

HDU - 1686 Oulipo KMP

Oulipo Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter ‘e’. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fai

weixin_51996479的博客 325

Hdu 1686 Oulipo[kmp]

题目链接:点击打开链接 这道题是裸的kmp。前两天对kmp学习了几天,感觉就是,next数组(也叫前缀数组),有点难实现。 不过照书打出来的很是简洁。 #include #include #include #include using namespace std; const int N=10003; const int M=1000004; char substring[N]

996

KMP HDU 1686 Oulipo

The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tout s

zero 295

hdu1686 Oulipo kmp

题目传送门 思路:kmp模板,稍微修改下    #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1000100; char p[maxn],t[maxn]; in...

weixin_30338497的博客 138

Oulipo HDU - 1686 KMP

问题: The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book: Tout avait Pair normal, mais tou...

HXX904的博客 325

HDU 1686 Oulipo [KMP]

Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:  Tout avait Pair no

Kelisiya 257

HDU 1686 Oulipo KMP

题意:给出一个模式串和一个待匹配串,求模式串在待匹配串中出现的次数 思路:KMP匹配成功后答案+1,返回fail位置继续匹配直到匹配到待匹配串尾 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<vector> #include&l...

qq_42397248的博客 189
上一篇: hdu-2203-亲和串(KMP模板)
下一篇: hdu-2087-剪花布条(KMP)
小k安达
博客等级 码龄10年 147粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值