poj 3461 Oulipo

[poj 3461]Oulipo[kmp] Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34693 Accepted: 14012DescriptionThe French author Georges Perec (1936–1982) once wrote a book, La disparition, without th 阅读详情

Oulipo
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 26226 Accepted: 10466

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算法模式匹配,这题特别容易超时,用改进后的next数组。


代码如下:

#include <cstdio>
#include <cstring>
const int maxn=1000010;
int next[10010];
char s[maxn];
char t[10010];
int lent,lens,ans; 
void get_next()
{
    int i=0,j=-1;
    next[0]=-1;
    while(i<lent)
    {
        if(j==-1||t[i]==t[j])
        {
            i++;
            j++;
			if(t[i]!=t[j])
				next[i]=j;
			else
				next[i]=next[j];
        }
        else
            j=next[j];
    }
}
int kmp(int i)
{
	int j=0;
    while(i<lens)
	{
		if(j==-1||t[j]==s[i])
		{
			i++;
			j++;
		}
		else
			j=next[j];
		if(j>=lent)
		{
			ans++;
			j=next[j];
		}
	}
	return ans;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
		ans=0;
        scanf("%s",t);
		lent=strlen(t);
		scanf("%s",s);
        lens=strlen(s);
		get_next();
		printf("%d\n",kmp(0));
    }
    return 0;
}


【数据集4】GSWP3数据集详解 简介GSWP3数据集 阅读详情

相关推荐

ORB-SLAM3单目摄像头

home/wheeltec-client/workspace/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src目录下找到:ros_mono.cc文件,打开找到并修改成我们自己摄像头的订阅话题(usb_cam/imahe_raw)即相机设置文件,官方提供的是Asus.yaml,可以另复制命名一个文件My_camera.yaml,将里面的相机参数修改成自己标定过的参数。sudoaptinstalllibeieng3-dev#命令安装的版本是eigen。

疯狂的石头 742

POJ3461 Oulipo

POJ3461 Oulipo 这一题是裸的kmp 总结几点: 字符串scanf读入不加& fail求的是文本串 代码: #include<iostream> #include<cstring> #include<cstdio> using namespace std; int n,ans; char w[10010],t[1000010]; int...

AlexTYJ的博客 179

Label Studio + SAM2分割半自动标注与yolo11训练

Label Studio + SAM2分割半自动标注与yolo11训练

schFallingCloud 1408

POJ 3461 Oulipo(乌力波)

POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K 【Description】 【题目描述】 The French author Georges Perec (1936–1982) once wrote a book, La disparition, without ...

274

STM32电机库(ST-MC-Workbench)实战指南——三电阻电流采样电路参数配置详解

本文详细解析了STM32电机库(ST-MC-Workbench)中三电阻电流采样电路的参数配置方法,涵盖电阻选型、放大增益计算、滤波时间优化等关键步骤。通过实战案例和调试技巧,帮助工程师快速掌握电流采样技术,提升电机控制系统的精度与稳定性。特别针对ST-MC-Workbench界面参数设置提供了详细指导。

weixin_29186249的博客 505

对称加密和非对称加密、公钥和私钥、单向认证和双向认证、数字签名、数字证书、根证书

文章目录1. 什么是公钥和私钥?2. 加密算法2.1 对称加密2.2 非对称加密2.2.1 非对称加密的重要性质2.2.2 非对称加密算法应用2.2.2.1 应用1 加密通信2.2.2.1.1 单向认证和双向认证2.2.2.1 应用2 数字签名3. 数字签名3.1 数字签名用法演示3.2 数字签名存在问题4. 数字证书(Digital Certificate)4.1 创建数字证书4.1.1 举例,CA如何给我们签发一个有效证书: 1. 什么是公钥和私钥? 摘自《什么是公钥和私钥?》 公钥(Public Ke

m0_45406092的博客 1万+

【KMP】POJ 3461 Oulipo

 POJ 3461 OulipoOulipo题目链接-&gt;http://poj.org/problem?id=3461Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 45665 Accepted: 18233DescriptionThe French author Georges Perec (1936–1982) once ...

荷叶田田 492

USB之ch376s数据手册

         最近师兄交给我一个项目,虽说刚学嵌入式起步,但上手一个项目怎说都是最好的快速学习方式。因为刚了解ch376s管理U盘的数据,所以先是看了ch376s的数据手册。那我就把数据手册直接放上来吧。。。。      1、概述 CH376 是文件管理控制芯片,用于单片机系统读写 U 盘或者 SD 卡中的文件。 CH376 支持 USB 设备方式和 USB 主机方式,并且内置了 USB 通...

iBGG的博客 6002

C++——KMP算法例题——Oulipo(POJ3461)

Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38073   Accepted: 15327 Description The French author Georges Perec (1936–1982) once wrote a book, La

McDonnell_Douglas的博客 854

开放自己本机的mysql允许别人连接

需要在左下角搜索记事本应用,右键以管理员身份运行,之后按照上述地址找到my.ini文件,ctrl+F搜索到[mysqld],修改或添加 bind-address 设置,将其更改为 0.0.0.0 或你的计算机的 IP 地址。打开 MySQL 的配置文件 my.ini。username和密码是第3步创建能从远程地址访问的用户和密码,ip地址是ipconfig查看的地址(前提是能ping通,才能连接该地址对应的数据库)。使用 MySQL 命令行连接到自己的数据库,并创建一个能够从远程地址访问的用户。

m0_74824687的博客 1167

(01)ORB-SLAM2源码无死角解析-(38) EPnP 算法原理详解→理论基础二:分情况求得beta初始解

讲解关于slam一系列文章汇总链接:史上最全slam从零开始,针对于本栏目讲解的(01)ORB-SLAM2源码无死角解析链接如下(本文内容来自计算机视觉life ORB-SLAM2 课程课件): (01)ORB-SLAM2源码无死角解析-(00)目录_最新无死角讲解:https://blog.youkuaiyun.com/weixin_43013761/article/details/123092196 文末正下方中心提供了本人联系方式,点击本人照片即可显示WX→官方认证{\color{blue}{文末正下方中心}

江南才尽江南山,年少无知年少狂! 1024

POJ3461 Oulipo

//4_6_2: Oulipo计算单词在文本中出现的次数 POJ3461 #include #include #include using namespace std; const int maxt = 1000000 + 10; const int maxw = 10000 + 10; int cnt; int nextval[maxw]; void KMP(char s

219

【Network Management】DCM模块唤醒网络是主动唤醒还是被动唤醒

DCM模块唤醒网络是主动唤醒还是被动唤醒

qq_36056498的博客 1537

机试之字符串匹配计数——POJ3461Oulipo

文章目录机试之字符串匹配计数——POJ3461Oulipo1、题目2、代码 机试之字符串匹配计数——POJ3461Oulipo 1、题目 题目链接:http://poj.org/problem?id=3461 题目大意为在文本text中找到单词W出现的次数,从而想到可以用KMP模式匹配的代码模板,再设置一个计数器cnt用来记录匹配成功的次数并返回输出即可 Oulipo Time Limit: 10...

李霁明的博客 329

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 3461 Oulipo(KMP:统计一个串出现的次数)

POJ 3461 Oulipo(KMP:计算一个串出现的次数) http://poj.org/problem?id=3461 题意:就是给你一个T串和P串,问你P串在T串中出现了多少次. 分析:直接套用KMP模板即可. AC代码: #include #include #include #include #include using namespace std; char T[10000

code 1313

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

POJ3461 Oulipo KMP裸题

POJ3461 Oulipo 很裸的KMP题目,求模式串在母串中的匹配次数。 不过我最开始用的cin T了 /(ㄒoㄒ)/~~ mdzz代码#include <iostream> #include <cstring> #include <cstdio> using namespace std;char s[1000005],a[10005]; int t; int next[10005];voi

Forjames的栏目 521

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ 3461 Oulipo

之前比赛的时候,一道KMP的题目没有做出来,很是郁闷。最近一两天仔细研究了一下KMP,收获不少。基本的KMP思想算法什么的就不再赘述了。只是我在网上找资料的时候发现KMP的失配数组(next[])有两个版本,但是几乎没有资料将这两个版本的next[]做一个较好的分析。于是,写了这篇blog,对这两类next[]做了一个简单的分析,希望对大家有帮助,也希望大家能指出其中的错误和不足。由于直...

ahqsqs3474的博客 121

POJ-3461 Oulipo

题目链接:http://poj.org/problem?id=3461 题目大意: 给你两个字符串p和s,求出p在s中出现的次数。 解题思路: 这道题跟POJ2406有点相似,那道题是求abcabcabc,则就是3次。 而这道题,abababa中aba出现了3次。 区别在于,2406求的是模式串的匹配问题,而这道题求的是主串和子串的匹配问题。 关键在于那个j=nextval[j]的意

飘过的小牛 7661

POJ 3461 Oulipo(字符串匹配,KMP算法)

题目来源:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49522   Accepted: 19665 Description The Frenc...

da_kao_la的博客 453

HDU 1686 Oulipo POJ 3461 Oulipo

KMP题。先输入模式串,再输入序列。求序列中有多少个模式串。这里求的是包含覆盖的情况。比如模式串是aa,序列是aaaaaa,要输出的结果是5而不是3。 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28707   Accepted: 11470

Moressette流沙的博客 477

Oulipo poj3461

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’a...

qq_43352073的博客 270

poj 3461 Oulipo

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, m...

lemon1090的博客 273

【POJ 3461】 Oulipo

【题目链接】 点击打开链接 【算法】 KMP 【代码】 #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale...

134
上一篇: poj 2752 Seek the Name, Seek the Fame
下一篇: poj 450 Oulipo
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值