#include<stdio.h>
#include<string.h>
typedef unsigned long long ULL;
const ULL Base1 = ;
const ULL Base2 = ; int test,n,m,x,y;
ULL ans;
char s[][],a[][];
ULL hash;
ULL temp[][],Temp[][];
ULL Gethash()
{
ULL c,d = ;
for(int i = ; i < x; ++i) {
c = ;
for(int j = ; j < y; ++j)
{
c = c*Base1 + a[i][j];
}
d = d * Base2 + c;
}
return d;
} void GetAns() {//把矩阵中的hash算出来,每个子矩阵的。
ULL t,a; // 算的时候与目标hash匹配判断一下....
t = ;
for(int i = ; i < y; ++i) t *= Base1;
for(int i = ; i < n; ++i) {
a = ;
for(int j = ; j < y; ++j) a = a*Base1 + s[i][j];
temp[i][y-] = a;
for(int j = y; j < m; ++j) {
temp[i][j]=temp[i][j-]*Base1-s[i][j-y]*t+s[i][j];
}
} t = ;
for(int i = ; i < x; ++i) t *= Base2;
for(int i = y-; i < m; ++i) {
a = ;
for(int j = ; j < x; ++j) a = a*Base2 + temp[j][i];
Temp[x-][i] = a;
if(a == hash) ans++;
for(int j = x; j < n; ++j) {
Temp[j][i] = Temp[j-][i]*Base2 - temp[j-x][i] * t + temp[j][i];
if(Temp[j][i]== hash) ans++;
}
}
} int main()
{
while(scanf("%d%d%d%d",&x,&y,&n,&m)!= EOF) {
//scanf("%d%d",&n,&m);
for(int i = ; i < x; ++i) scanf("%s",a[i]);
//scanf("%d%d",&n,&m);
for(int i = ; i < n; ++i) scanf("%s",s[i]);
hash = Gethash();
ans = ;
GetAns();
printf("%llu\n",ans);
}
return ;
}

LA 6893 矩阵HASH (模板)的更多相关文章

  1. LA 6893 The Big Painting(矩阵Hash)

    https://vjudge.net/problem/UVALive-6893 题意: 给出一个小矩阵和大矩阵,在大矩阵中能找到相同的小矩阵. 思路: 矩阵Hash,先对小矩阵计算出它的Hash值,然 ...

  2. 矩阵hash + KMP - UVA 12886 The Big Painting

    The Big Painting Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=88791 M ...

  3. [poj] 3690 Constellations || 矩阵hash

    原题 在大矩阵里找有几个小矩阵出现过,多组数据 将t个矩阵hash值放入multiset,再把大矩阵中每个hash值从multiset里扔出去,这样最后剩在multiset里的值就是没有找到的小矩阵, ...

  4. 线段树、KMP、HASH模板

    线段树 #include<cstdio> using namespace std; int n,p,a,b,m,x,y,ans; struct node { int l,r,w,f; }t ...

  5. hdu 4622 Reincarnation 字符串hash 模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...

  6. 牛客网训练1--------矩阵 (二份+二维矩阵hash)

    不懂hash的话:https://www.cnblogs.com/ALINGMAOMAO/p/10345850.html 思路:对于一个大矩阵的每一个子矩阵都对应着一个hash值k, 当k出现2次以上 ...

  7. [luogu P1962] 斐波那契数列(带快速幂矩阵乘法模板)

    题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数) 题目描述 请 ...

  8. LA 4670 (AC自动机 模板题) Dominating Patterns

    AC自动机大名叫Aho-Corasick Automata,不知道的还以为是能自动AC的呢,虽然它确实能帮你AC一些题目.=_=|| AC自动机看了好几天了,作用就是多个模式串在文本串上的匹配. 因为 ...

  9. LA 3704 (矩阵快速幂 循环矩阵) Cellular Automaton

    将这n个格子看做一个向量,每次操作都是一次线性组合,即vn+1 = Avn,所求答案为Akv0 A是一个n*n的矩阵,比如当n=5,d=1的时候: 不难发现,A是个循环矩阵,也就是将某一行所有元素统一 ...

随机推荐

  1. AJAX工作原理与缺点

    1.概念:什么是AJAXAJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.2.为什么要使用他 ...

  2. 066、Weave如何与外网通信?(2019-04-09 周二)

    参考https://www.cnblogs.com/CloudMan6/p/7500550.html   Weave是一个私有的vxlan网络,默认与外部网络隔离.外部网络如何才能访问到weave中的 ...

  3. window.open post

    前端代码 expExcel(){ window.open(PreURL+'company_list_exp?keyword='+this.keyword+'&area_code='+this. ...

  4. git步骤

    1.New一个Repositories 2.拿到这个仓库的URL 3.git clone https://github.com/zhuobo/new.git 4.进入到clone下来的文件夹,然后gi ...

  5. Python正则的贪婪和非贪婪示例

    贪婪匹配 import re info = """ saas12 [STREAM] codec_type=audio111 [/STREAM]-- [STREAM] co ...

  6. C#调用C++导出类的一个实例

    一直认为带导出类dll的只有VC自己可以调用,其它编程语言无法调用,今天看到一篇文章才知道自己错了.https://blog.csdn.net/huiyouyongdeyu2011/article/d ...

  7. CC2541设置中断输入模式

    //P0.0 /* SW_6 is at P0.1 */#define HAL_KEY_SW_6_PORT P0#define HAL_KEY_SW_6_BIT BV(0)#define HAL_KE ...

  8. 简单回射程序之处理accept返回EINTR错误的服务器程序版本

    #include <stdio.h> #include <stdlib.h> #include <time.h> #include <errno.h> ...

  9. 十二、文件和目录——Linux文件系统结构

    12.1 Linux文件系统结构 12.1.1 文件操作基本元素 文件操作相关的最基本元素是:目录结构,索引节点和文件的数据本身 目录结构(目录项) 索引节点(i 节点) 文件的数据 12.1.2 文 ...

  10. S02-45 struts2 最新漏洞 学习记录

    今天和朋友一起学习S02-45.按照官方解释:Content-Type:multipart/form-data 这个条件成立的时候,能够触发jakarta的上传漏洞.可能导致远程执行任意代码或者上传文 ...