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第二弹~

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
char a[1000007],b[10007];
int next[10007];
int c;
int m,n;
void getnext()
{int i=0;int j=-1;next[0]=-1;while(i<n){if(j==-1||b[j]==b[i]){i++;j++;if(b[j]!=b[i])next[i]=j;elsenext[i]=next[j];//j回溯}elsej=next[j];//j回溯}
}int kmp()
{int i=0,j=0;while(i<m&&j<n){if(j==-1||a[i]==b[j]){i++;j++;}elsej=next[j];if(j==n){j=next[j];c++;}}return c;
}
int main()
{int test;scanf("%d",&test);getchar();while(test--){memset(next,0,sizeof(next));c=0;gets(b);gets(a);m=strlen(a);n=strlen(b);getnext();printf("%d\n",kmp());}return 0;
}

HDU1686——Oulipo相关推荐

  1. POJ3461 HDU1686 Oulipo题解

    代码来源:TYUT_YancyKahn AC的C++语言程序如下: #include <iostream> #include <cstdio> #include <cst ...

  2. ICPC程序设计题解书籍系列之五:吴永辉:《数据结构编程实验》(第2版)

    第1章 简单计算 UVALive2362 POJ1004 HDU1064 ZOJ1048 Financial Management[数学+水题] - 海岛Blog - CSDN博客 POJ1552 H ...

  3. MUV LUV UNLIMITED(ccpc 秦皇岛2019)

    MUV LUV UNLIMITED(ccpc 秦皇岛2019) 题目描述 There are few entertainments in United Nations 11th Force, Paci ...

  4. Oulipo(欧力波)(经典kmp模板题) HDU-1686

    题目:Oulipo(欧力波) 中文大意 The French author Georges Perec (1936�C1982) once wrote a book, La disparition, ...

  5. HDU - 1686 Oulipo

    https://vjudge.net/problem/HDU-1686 HDU - 1686 Oulipo 题目 分析 AC代码 题目 The French author Georges Perec ...

  6. Oulipo (KMP算法)

    Oulipo (KMP算法) 题目链接:HDU-1686 题目: Oulipo Problem Description The French author Georges Perec (1936–19 ...

  7. KMP POJ 3461 Oulipo

    题目传送门 1 /* 2 题意:问一个串在另一个串出现的次数(可重复) 3 KMP:模板题 4 */ 5 /********************************************** ...

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

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

  9. Oulipo (KMP出现次数)

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

最新文章

  1. jenkins自动打包设置打包文件脚本
  2. NSPredicate的使用
  3. 卷机神经网络的可视化(可视化中间激活)
  4. esp32树莓派_用树莓派 DIY 宠物自动喂食机,再也不用担心家里的萌宠了
  5. Jmeter中的几个重要测试指标释义
  6. pyplot设置刻度字体大小以及标签字体大小
  7. 同步异步线程进程的一些思考
  8. dcs world f15c教学_陕西【精细化工dcs控制】施工
  9. topsis法_topsis法量化多个评价指标,找出最优方案
  10. SpringBoot使用AOP记录接口操作日志
  11. Fragment、FragmentActivity、Fragment生命周期及Fragment组件穿透
  12. 如何测试工业以太网线缆(利用FLUKE DSX-8000)?
  13. AXI FULL协议学习与仿真
  14. Notepad++ 一键格式化php代码
  15. dlna android电视,DLNA怎么用?DLNA连接智能电视和电脑的方法分享
  16. 富途最新股权曝光:腾讯持股21% 李华有67.4%投票权
  17. 备忘 Linux 快速分区
  18. 15.PG分区表-内置分区表
  19. Ubuntu桌面自动切换壁纸(不用写脚本和xml配置文件)
  20. matlab饼图正圆,怎样用matlab画饼图

热门文章

  1. 本体技术视点 | SocialFi 如何解决 Web3 社交中的声誉问题?
  2. adb通过wifi连接android设备(魅族note3)
  3. jav读取excel文件
  4. 127.0.0.1的1521端口通,固定IP1521端口不通
  5. java语法基础练习题
  6. 计算机如何实施高效课堂 提高知识转化效率,浅谈实施高效课堂的策略
  7. 领奖台数/三元数组对
  8. 【深度学习】召回过程优化--BM25
  9. 利用AidLux实现热成像电力巡检
  10. ffmpeg实现自定义封面图