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
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int  b[10005];//之前用next[10005]CE,不明确,可能有函数吧。。。,好坑
char ch1[1000005],ch2[1000005];
void get_next(int len1)
{int i=0,j=-1;b[0]=-1;while(i<len1){if(j==-1||ch1[i]==ch1[j]){i++;j++;if(ch1[i]==ch1[j])b[i]=b[j];elseb[i]=j;}elsej=b[j];}
}
int  kmp(int len1,int len2)
{int i=0,j=0,k=0;get_next(len1);while(i<len2){if(j==-1||ch2[i]==ch1[j]){i++;j++;}else{j=b[j];}if(j==len1){k++;}}return k;
}int main()
{int n;cin>>n;getchar();while(n--){cin>>ch1>>ch2;int len1,len2;len1=strlen(ch1);len2=strlen(ch2);get_next(len1);cout<<kmp(len1,len2)<<endl;}return 0;
}

转载于:https://www.cnblogs.com/nefu929831238/p/5286110.html

HDU1686:Oulipo相关推荐

  1. HDU1686——Oulipo

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

  2. POJ3461 HDU1686 Oulipo题解

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

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

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

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

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

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

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

  6. HDU - 1686 Oulipo

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

  7. Oulipo (KMP算法)

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

  8. KMP POJ 3461 Oulipo

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

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

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

  10. Oulipo (KMP出现次数)

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

最新文章

  1. Windows Server 2008 without Hyper-V 版本
  2. 谷歌为URL缩短服务goo.gl开放API
  3. python生成条形图-Python处理JSON数据并生成条形图
  4. wxWidgets:wxArchiveIterator类用法
  5. SAP Basic T-Code
  6. 相机标定(笔记本摄像头和usb相机)
  7. 自动打印照片是如何实现的
  8. 人无信则不立,您了解自己的信用情况吗?
  9. 对焦过程中消除摩尔纹
  10. 电脑版适合什么插件HTML,推荐一些好用的Chrome插件
  11. spark 终止 运行_如何在数据源运行ou时停止spark流
  12. GEE实战 | 各种指数分析(植被、水体、建筑)
  13. POJ Haybale Guessing
  14. 传统算法与神经网络算法,常见的神经网络算法有
  15. spss基础-5.8
  16. 安全研究 # 课题:二进制成分分析(Binary SCA)
  17. 双路微型计算机,十二核心至尊 Intel Xeon E5-2697 v2
  18. 软件测试主管应具备的素质,软件测试人员应具备的素质
  19. arduino 多个超声波模块HC-SR04 Newping.h库的使用——摆脱万恶的阻塞等待
  20. 主键,超键,候选键,外键的含义

热门文章

  1. python文本风格_Python的代码风格
  2. 【2020牛客寒假基础算法训练营】第四场总结
  3. 【BZOJ3916】friends(hash+分情况讨论)
  4. 求N!二进制中末尾1的位置(类似于求N!中有多少个5的问题)
  5. 列转行 带逗号_Excel 统计压岁钱?按逗号拆分单元格且纵向排列,分离中文和数字...
  6. 支持向量机SVM原理(参数解读和python脚本)
  7. MATLAB--卡尔曼滤波
  8. socket长连接server c语言,使用socket建立长连接
  9. 解决XCode运行app在模拟器上,提示模拟器不存在
  10. Transformer-XL、Vanilla Transformer