POJ 3461 Oulipo(字符串hash)
字符串hash判断字符串是否相等。
code
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; typedef unsigned long long uLL;
const uLL B = ; uLL f[];
uLL Hash[];
char a[],b[]; int main () {
int T;
scanf("%d",&T);
f[] = ;
for (int i=; i<=; ++i) f[i] = (f[i-] * B);
while (T--) {
int ans = ;
scanf("%s%s",a,b);
int s1 = strlen(a),s2 = strlen(b);
uLL Ha = ;
for (int i=; i<s1; ++i) {
Ha = (Ha*B+a[i]);
}
Hash[] = b[];
for (int i=; i<s2; ++i) {
Hash[i] = Hash[i-]*B+b[i];
}
for (int i=; i<=(s2-s1); ++i) {
int l = i,r = l+s1-;
uLL Hb = Hash[r]-Hash[l-]*f[s1];
if (Ha == Hb) ans++;
}
printf("%d\n",ans);
}
return ;
}
POJ 3461 Oulipo(字符串hash)的更多相关文章
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...
- 字符串hash - POJ 3461 Oulipo
Oulipo Problem's Link ---------------------------------------------------------------------------- M ...
- POJ 3461 Oulipo
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3865 - Database 字符串hash
[题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- Palindrome POJ - 3974 (字符串hash+二分)
Andy the smart computer science student was attending an algorithms class when the professor asked t ...
- POJ 3461 Oulipo(模式串在主串中出现的次数)
题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即 ...
随机推荐
- 阻塞IO, 非阻塞IO, 同步IO,异步IO
阻塞IO, 非阻塞IO, 同步IO,异步IO 介绍 先说明几个概念 用户空间与内核空间 为了保证用户进程不能直接操作内核(kernel),保证内核的安全,操心系统将虚拟空间(内存)划分为两部分,一部分 ...
- 【技巧】如何使用UltraEdit删掉某些行并且不留空行
例: 在S1这个文件中我想要把所有B6 96 FD 2E 49 96 2 D2的行删掉. 首先,查找这些序列,执行替换命令,替换为的内容不写. 点击“全部替换”之后,发现在原来的位置多了一行空行. 接 ...
- pcp分布式监控工具
已经集成在redhat6.x版本里 http://pcp.io
- ansible使用8-Best Practices
Content Organization production # inventory file for production servers stage # inventory file for s ...
- CMAKE 安装
下载 解压 https://cmake.org/download/ https://cmake.org/files/v3.7/cmake-3.7.1.tar.gz yum install gcc - ...
- 关于定义顺序和内存分配的关系--记一道不严谨的C语言题
include<stdio.h> #include<iostream> int main() { char a[] = "123"; char b[] = ...
- Selenium入门7 内嵌框架iframe
如果网页内嵌iframe,那么iframe里的元素是无法直接定位的,需要使用switch_to.frame进入frame操作: 之后需要再操作页面上非嵌入在iframe里的元素,需要使用switch_ ...
- C++学习之虚析构函数
什么样的情况下才需要虚析构函数? 类需要控制自己的对象执行一系列操作时发生什么样的行为,这些操作包括:创建(对象).拷贝.移动.赋值和销毁.在继承体系中,如果一个类(基类或其派生的类)没有定义拷贝控制 ...
- IOS 设置颜色的的详情
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- phpmyadmin 打开数据表较多,数据量较大的数据库时出现超时的解决办法
用phpmyadmin打开数据表较多,数据量较大的数据库时,会出现超时,或者等半天打开了说数据库没有表.并且即便打开了,再进行其他浏览,编辑,sql等操作,页面也是相当慢的,慢等几乎无法忍受.这里慢也 ...