Oulipo

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

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   ....经典题

思路清晰,就不多说啦!...

就是求目标串在主串中出现几次,即匹配几次,,.

代码:

 /*@coder 龚细军*/
#include<iostream>
#include<string>
#include<vector>
using namespace std; int main()
{
int t,i,j;
string pw,ps;
cin>>t;
while(t--)
{
i=,j=-;
cin>>pw>>ps; /*pw作为目标串,ps作为主串*/
int lenpw=pw.length();
int lenps=ps.length();
vector<int>next(lenpw+,);
next[i]=-;
while(i<lenpw)
{
if(j==-||pw[i]==pw[j])
{
++i;
++j;
if(pw[i]!=pw[j])
next[i]=j;
else
next[i]=next[j];
}
else
j=next[j];
}
i=-,j=-;
int ans=;
while(i<lenps)
{
if(j==-||pw[j]==ps[i])
{
++i;
++j;
}
else
j=next[j];
if(j==lenpw)
ans++;
}
printf("%d\n",ans);
}
return ;
}

HDUOJ -----1686的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. FZU 1686 神龙的难题 (重复覆盖)

    Problem 1686 神龙的难题 Accept: 397    Submit: 1258Time Limit: 1000 mSec    Memory Limit : 32768 KB  Prob ...

  3. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  4. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  5. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  6. hdu 1686 Oulipo KMP匹配次数统计

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...

  7. FZU 1686 神龙的难题 (DLX)

    神龙的难题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  8. PQJ 1686(栈栈栈)

    PQJ  1686(栈栈栈) 用栈解决问题 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  9. FZU 1686 神龙的难题(DLX反复覆盖)

    FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...

随机推荐

  1. idea 配置简单web

    1.创建Facets 创建web的facets,可修改web的目录路径,如java目录 2.创建artifacts 创建web aplication exploded ,添加lib包到web-inf, ...

  2. Maximum Likelihood Method最大似然法

    最大似然法,英文名称是Maximum Likelihood Method,在统计中应用很广.这个方法的思想最早由高斯提出来,后来由菲舍加以推广并命名. 最大似然法是要解决这样一个问题:给定一组数据和一 ...

  3. @JVM垃圾收集器种类

    为什么要分代 之所以采用分代垃圾收集机制是因为不同的对象生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大量的对象,其中有些对 ...

  4. vue项目ide(vue项目环境搭建)

    一.先介绍一下我接下来要做的项目 项目:ide可视化工具 技术应用: Vue2.0(js框架):https://cn.vuejs.org/ ElementUi(饿了吗ui框架基于vue的):http: ...

  5. Informatica 常用组件Lookup之三 关系和平面文件查找

    创建查找转换时,您可以选择使用关系表或平面文件作为查找源. 关系查找 使用关系表作为查找源来创建查找转换时,您可以使用 ODBC 连接到查找源并导入表定义作为查找转换的结构. 仅可对关系查找使用以下选 ...

  6. Eclipse上传代码到GitHub

    平时工作学习中难免会在Github搜索一下开源的Android代码, Android系统本身的代码就是托管在GitHub上,如果平时随手做了一个Demo,托管在云盘感觉不入流,如果平时自己一时兴起写了 ...

  7. Git 忽略规则 .gitignore文件 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 30: illegal multibyte sequence

    昨天用用python3写个日志文件,结果报错UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 30: ...

  9. 如何在Linux中发现IP地址冲突

    导读 你们都知道什么是IP地址,是吧?它们被分配给网络上的设备来代表它们.它们通过DHCP服务器分配并且会经常改变.现在有两种IP地址.动态的一种会经常改变(几天一次),而静态的就如它的名字那样是静态 ...

  10. RAID5工作原理介绍

    RAID 5是一种存储性能.数据安全和存储成本兼顾的存储解决方案.以四个硬盘组成的RAID 5为例,其数据存储方式如图4所示:图中,P0为D0,D1和D2的奇偶校验信息,P1为D3,D4,D5的奇偶校 ...