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字符串即 ...
随机推荐
- 323. Number of Connected Components in an Undirected Graph (leetcode)
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- Zabbix 2.4安装部署
目 录 第1章 Zabbix Server安装... 1 1.1 Zabbix Server环境... 1 1.2 Zabbix Server软件... 1 1.3 Zabbix server配置. ...
- Breaking Biscuits(模板题-求凸边形的宽)
Breaking Biscuits 时间限制: 1 Sec 内存限制: 128 MB Special Judge提交: 70 解决: 26[提交] [状态] [讨论版] [命题人:admin] ...
- mysql数值函数
abs(x) -- 绝对值 abs(-10.9) = 10 format(x, d) -- 格式化千分位数值 format(1234567.456, 2) = 1,234,567.46 ceil(x) ...
- 浅谈Docker
一.为什么使用Docker 软件开发最大的麻烦事之一,就是环境配置.很多人想到,能不能从根本上解决问题,软件可以带环境安装? 也就是说,安装的时候,把原始环境一模一样地复制过来. 目前有两个主流解决方 ...
- 【杂题总汇】Codeforces-67A Partial Teacher
[Codeforces-67A]Partial Teacher 上周刷了一大堆小紫薯的动态规划的题
- Exception occurred during processing request: The given object has a null identifier: com.zsn.crm.Model.SaleVisit; nested exception is org.hibernate.TransientObjectException: The given object has a nu
edit.jsp页面没有加入隐藏字段 id ,导致模型驱动封装时缺少id ,,调用update更新数据库时出错!
- MySQL5.6基于MHA方式高可用搭建
master 10.205.22.185 #MHA node slave1 10.205.22.186 #MHA node+MHA manager slave2 10.205.22.187 #MH ...
- Angular环境配置
1.安装node.js 访问官方网站:https://nodejs.org/en/下载node.js,直接下一步安装即可.安装完成打开cmd命令窗口输入node -v出现node版本号安装成功. 2. ...
- linux面试集
shell:1.$# 和 $*之类的特殊变量 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n是一个数字,表示第几个参数.例如,第一个参数就是$1 $# 传递给脚本或 ...