https://vjudge.net/problem/HDU-1686

HDU - 1686 Oulipo

  • 题目
  • 分析
  • AC代码

题目

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应用

AC代码

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e6+10;
int n,m,t;
int ne[N];
char s[N],p[N];
int main()
{cin>>t;while(t--){scanf("%s",p);scanf("%s",s);n=strlen(s);m=strlen(p);ne[0]=-1;for(int i=0,j=-1;i<=m;){if(j==-1 || p[i]==p[j]){i++,j++;ne[i]=j;}elsej=ne[j];}int ans=0;for(int i=0,j=0;i<n;){if(j==-1 || s[i]==p[j]){i++;j++;}elsej=ne[j];if(j==m)ans++;           }cout<<ans<<endl;}return 0;
}

HDU - 1686 Oulipo相关推荐

  1. HDU 1686 Oulipo【kmp求子串出现的次数】

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  2. hdu 1686 Oulipo(kmp)

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  3. HDU - 1686 Oulipo KMP

    Oulipo Problem Description The French author Georges Perec (1936–1982) once wrote a book, La dispari ...

  4. KMP - Oulipo - HDU - 1686

    HDU - 1686 The French author Georges Perec (1936–1982) once wrote a book, La disparition, without th ...

  5. Oulipo HDU - 1686(哈希或KMP)匹配字符串

    题意:字符串匹配:寻找字符串S中,字符串T出现的次数 思路:KMP或哈希 The French author Georges Perec (1936–1982) once wrote a book, ...

  6. Oulipo HDU - 1686 (kmp初见讨伐!)

    题目链接 题意:给你两个字符串s,t.让你求在s中t出现了多少次. 解题思路: 先写前缀函数(前缀函数的写法点这里了解) 然后就是常规KMP模板了.统计答案时重置pos_t的位置. 错误原因:对重置p ...

  7. Oulipo HDU - 1686 (使用扩展kmp进行讨伐!)

    题目链接 题意:给你两个字符串s,t.让你求在s中t出现了多少次. 解题思路: kmp做法点这里 使用扩展kmp.构建一个新字符串k=t+▲+s ▲为分隔符,保证不会影响s求z函数. 对k使用扩展km ...

  8. HDU 1618 Oulipo KMP解决问题的方法

    鉴于两个字符串,寻找一个字符串的频率,另一个字符串出现. 原版的kmp另一个陷阱.以下凝视了,标不是踩着好,有加班一定几率,也有机会错误,根据不同的字符串可以是详细. 变化看起来像一个,kmp速度是非 ...

  9. hdu 1686(标准的kmp,可当模板)

    /*题意:给两个字符串a,s,判断a在s里出现的个数*/#include <stdio.h> #include <string.h>int next[10005]; char ...

最新文章

  1. grunt入门讲解1:grunt的基本概念和使用
  2. 优达学城数据分析师纳米学位——P3项目知识点整理及代码分析 xml文件解析
  3. tensorflow常见函数
  4. 数字孪生+交通,到底有啥用?
  5. oledbdataadapter 取不到数据 plsql能取到 date_Python3 CookBook | 数据结构和算法(二)...
  6. sklearn分类任务模型评价指标汇总与AUC-ROC曲线及代码示例
  7. 10个精妙的Java编码最佳实践
  8. 用商业智能BI软件的好处有哪些
  9. C# 文件查询管理器
  10. 【最全】微信支付宝小程序蓝牙API开锁全流程
  11. css003 选择器:明确设置哪些样式
  12. m基于BP神经网络的障碍物避障和路线规划matlab仿真
  13. 北航、商汤、UCSD 提出首个点云二值网络 BiPointNet(ICLR2021)
  14. 获取海拔高度. 实时气压
  15. Go 面向接口编程实战
  16. 中石油布局天然气商储 天然气国家储备有望
  17. 辐射强度和辐射亮度_如何在“辐射4”中隐藏“创意俱乐部新闻”垃圾邮件
  18. 三级医院信息互联互通标准化成熟度测评要求
  19. Warning: ReactDOM.render is no longer supported in React 18.
  20. 计算机错误678,宽带连接错误678,教您宽带连接错误678怎么解决

热门文章

  1. python绘制蟒蛇_Python基本图形绘制——蟒蛇绘制
  2. ST-GCN/AS-GCN报错cannot import name “import_class“
  3. 春招:我居然三天就拿到了offer?
  4. yolov5控制测试视频窗口大小
  5. echarts 日历图calender
  6. linux 网桥 权限,如何在 Ubuntu 上搭建网桥
  7. OO之美:好代码和坏代码
  8. 【Pygame实战】疫情期间给不能出门的你推荐一款爽游 《消灭病毒保卫城市》【强推】愿早日结束
  9. bbedit php,BBEdit for Mac(最好用的HTML文本编辑器)
  10. 硬件设计基础----运算放大器