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字符串即 ...
随机推荐
- linux服务器tomcat启动时,不能加载项目
---恢复内容开始--- 问题描述:tomcat启动时候,能够成功启动但是项目不能加载,查看catalina.out后出现以下的错误 due to a StackOverflowError. Poss ...
- nginx-1.12.2编译安装指导
nginx-1.12.2编译安装 下载源码包 安装 安装后配置 下载源码包 下载地址:http://nginx.org/en/download.html nginx-1.12.2:http://ngi ...
- 常用HTML富文本编辑器
常用的HTML富文本编译器UEditor.CKEditor.TinyMCE.HTMLArea.eWebEditor.KindEditor简介 这篇文章主要介绍了常用的HTML富文本编译器UEdit ...
- Linux CentOS下部署Java Web项目
本文讲解如何在Linux CentOS下部署Java Web项目的步骤. 一.环境准备: (1)Linux CentOS (2)apache-tomcat-9.0.10 (3)XShell 二.启动t ...
- *521. Longest Uncommon Subsequence I (bit manipulation 2^n)
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- cocos2d-x 3.0 创建项目
cocos2d-x 3.0 创建项目 点击打开链接
- Poj(2312),坦克大战,BFS的变形
题目链接:http://poj.org/problem?id=2312 挺有趣的一道题目,然而很容易WA,我就WA了一次,虽然我Debug的时候已经知道哪里出问题了,就是比如说我搜到B和E时,从B搜第 ...
- linux命令之grep命令
grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...
- HttpContext.RewritePath
定义:使用给定路径重写 URL.就是可以跳转到指定的URL. 也可以做为伪静态的跳转.具体如下. 他的重载 ①新建一个页面,放两个链接到另一个页面,注意给的链接 ②在 global.asax 文件中 ...
- C#浏览器中在线操作文档
源码地址:https://github.com/SeaLee02/FunctionModule 文件夹 UploadFiles/WebDemo/COM/OnlineEdit.aspx 就是源码 用 ...