【poj3461】 Oulipo
http://poj.org/problem?id=3461 (题目链接)
题意
求一个字符串在另一个字符串中出现的次数。
Solution
KMP裸题,太久没写过了,都忘记怎么求next数组了。。水一发→_→
细节
next[0]=-1。
代码
// poj3461
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=1000010;
char s[maxn],t[maxn];
int next[maxn]; void calnext() {
next[0]=-1;
for (int i=1,j=-1;s[i];i++) {
while (j!=-1 && s[i]!=s[j+1]) j=next[j];
if (s[j+1]==s[i]) j++;
next[i]=j;
}
}
int main() {
int T;scanf("%d",&T);
while (T--) {
scanf("%s%s",s,t);
int sum=0;
calnext();
for (int i=0,j=-1;t[i];i++) {
while (j!=-1 && s[j+1]!=t[i]) j=next[j];
if (s[j+1]==t[i]) j++;
if (!s[j+1]) sum++,j=next[j];
}
printf("%d\n",sum);
}
return 0;
}
【poj3461】 Oulipo的更多相关文章
- 【POJ3461】Oulipo
题面 The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter ...
- 【POJ3461】【KMP】Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- 【POJ3461】Olipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- 【KMP】Oulipo
KMP算法 求串内匹配数,计数时返回next[]位置. Problem Description The French author Georges Perec (1936–1982) once wro ...
- 【题解】Oulipo
题目描述 给出两个串S1,S2(只有大写字母),求S1在S2中出现了多少次. 例如:S1=“ABA”,S2=“ABABA”,答案为2. 输入T组数据,对每组数据输出结果. 输入输出格式 输入格式 第一 ...
- 【POJ 3461】 Oulipo
[题目链接] 点击打开链接 [算法] KMP [代码] #include <algorithm> #include <bitset> #include <cctype&g ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 【原】谈谈对Objective-C中代理模式的误解
[原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...
- 【原】FMDB源码阅读(三)
[原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...
随机推荐
- Centos5.8 安装 Redmine
安装Ruby 到 /opt/ruby-2.0.0 -p481.tar.gz cd ruby--p481 ./configure --prefix=/opt/ruby- sudo make sudo m ...
- codevs 2801 LOL-盖伦的蹲草计划
时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 众所周知,LOL这款伟大的游戏,有个叫盖伦的英雄.他的伟大之处在于他特别喜欢蹲 ...
- Swagger 增加 DocumentFilter 隐藏不需要显示的接口
services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1& ...
- git 找回丢失的commit
From : http://dmouse.iteye.com/blog/1797267 git 的错误操作,导致丢失了重要的commit,真是痛不欲生: 最后通过git神器终于找回了丢失的commit ...
- XStream、JAXB 日期(Date)、数字(Number)格式化输出xml
XStream.Jaxb是java中用于对象xml序列化/反序列化 的经典开源项目,利用它们将对象转换成xml时,经常会遇到日期(Date).数字按指定格式输出的需求,下面是使用示例: 一.日期字段格 ...
- 什么是API
我们从API的功能.分类.设计.实现.用户来看什么是API. API是应用程序组件之间通信的接口 --wiki:Application Programming Interface In compute ...
- C/C++实践笔记_001Helloworld
1.void返回值为空,int返回值Linux c,c++中,Main函数可以返回也可以不返回,普通函数必须返回.C编译松散,很容易结果出错,C++编译严格一些,结果一般会正确C语言不返回不会报错,但 ...
- Python【map、reduce、filter】内置函数使用说明(转载)
转自:http://www.blogjava.net/vagasnail/articles/301140.html?opt=admin 介绍下Python 中 map,reduce,和filter 内 ...
- 转一篇关于Unity的PlayMaker
这篇文章转自http://va.lent.in/should-you-use-playmaker-in-production/ 此文作者大概深受其苦,吐槽了playmaker的多个蛋疼的地方,这其实说 ...
- Js中Prototype、__proto__、Constructor、Object、Function关系介绍
一. Prototype.__proto__与Object.Function关系介绍 Function.Object:都是Js自带的函数对象.prototype,每一个函数对象都有一个显式的proto ...