HDU1686——Oulipo
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.
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.
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相关推荐
- POJ3461 HDU1686 Oulipo题解
代码来源:TYUT_YancyKahn AC的C++语言程序如下: #include <iostream> #include <cstdio> #include <cst ...
- ICPC程序设计题解书籍系列之五:吴永辉:《数据结构编程实验》(第2版)
第1章 简单计算 UVALive2362 POJ1004 HDU1064 ZOJ1048 Financial Management[数学+水题] - 海岛Blog - CSDN博客 POJ1552 H ...
- MUV LUV UNLIMITED(ccpc 秦皇岛2019)
MUV LUV UNLIMITED(ccpc 秦皇岛2019) 题目描述 There are few entertainments in United Nations 11th Force, Paci ...
- Oulipo(欧力波)(经典kmp模板题) HDU-1686
题目:Oulipo(欧力波) 中文大意 The French author Georges Perec (1936�C1982) once wrote a book, La disparition, ...
- HDU - 1686 Oulipo
https://vjudge.net/problem/HDU-1686 HDU - 1686 Oulipo 题目 分析 AC代码 题目 The French author Georges Perec ...
- Oulipo (KMP算法)
Oulipo (KMP算法) 题目链接:HDU-1686 题目: Oulipo Problem Description The French author Georges Perec (1936–19 ...
- KMP POJ 3461 Oulipo
题目传送门 1 /* 2 题意:问一个串在另一个串出现的次数(可重复) 3 KMP:模板题 4 */ 5 /********************************************** ...
- Oulipo HDU - 1686(哈希或KMP)匹配字符串
题意:字符串匹配:寻找字符串S中,字符串T出现的次数 思路:KMP或哈希 The French author Georges Perec (1936–1982) once wrote a book, ...
- Oulipo (KMP出现次数)
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
最新文章
- linux 修改ip地址_Day.19 变更IP地址
- console.log打印没有效果
- java reflectionutils_Spring中的各种Utils(五):ReflectionUtils详解(转载)
- 手机耗电统计app_华为手机有哪些功能关掉比较好?
- 装逼神器,5 行 Python 代码 实现一键批量扣图,你get到了吗
- 【STM32】HAL库 STM32CubeMX教程十五---FMC-SDRAM(一)
- 网信办拟规定:平台未经用户同意不得强制订阅关注账号;Twitter回应大范围宕机;Krita 4.4.0发布|极客头条
- 写在随手记2亿美金融资之后,财务金融是伪命题还是真风口?
- 深入解析条件变量(condition variables)
- Weblogic配置和部署
- 计算机一插u盘就丢失数据,u盘里面的数据会不会消失,教您u盘里面的数据消失怎么办...
- 3D模型在线转换,Solidworks版本转换
- 计算机标准体重计算公式,项目2:就拿胖子说事---(2)计算出标准体重,当超重时,请给出提示...
- 是时候拥抱ViewBinding了~
- Windows设置程序开机自启动
- win11如何快速关机 windows11快捷键关机的设置方法
- centos7.1 修改selinux相关机制后出现开机失败,报错faild to load selinux policy freezing
- 解决导出excel导出名字乱码
- 华为AR路由器无法上网解决办法
- 1124. Raffle for Weibo Followers
热门文章
- Python解决中文显示成框框的方法
- UNI-APP,实现给字符串中部分字符、子串添加样式(颜色,字号等)
- 魔幻蓝诗@画板3.0
- 每天干的啥?(2018.10)
- SpringBoot 2.0 中 HikariCP 数据库连接池原理解析
- 数据库连接池原理介绍
- bui java_bui-bootstrap java中比较好看的后台那界面,简介 管理 Develop 238万源代码下载- www.pudn.com...
- 2021年保育员(初级)考试题及保育员(初级)最新解析
- 打破咖啡外卖边界,星巴克和美团合作带来哪些启发?
- Google官网,Google android的产品线(important)