LA 6893 矩阵HASH (模板)
#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 (模板)的更多相关文章
- LA 6893 The Big Painting(矩阵Hash)
https://vjudge.net/problem/UVALive-6893 题意: 给出一个小矩阵和大矩阵,在大矩阵中能找到相同的小矩阵. 思路: 矩阵Hash,先对小矩阵计算出它的Hash值,然 ...
- 矩阵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 ...
- [poj] 3690 Constellations || 矩阵hash
原题 在大矩阵里找有几个小矩阵出现过,多组数据 将t个矩阵hash值放入multiset,再把大矩阵中每个hash值从multiset里扔出去,这样最后剩在multiset里的值就是没有找到的小矩阵, ...
- 线段树、KMP、HASH模板
线段树 #include<cstdio> using namespace std; int n,p,a,b,m,x,y,ans; struct node { int l,r,w,f; }t ...
- hdu 4622 Reincarnation 字符串hash 模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同 ...
- 牛客网训练1--------矩阵 (二份+二维矩阵hash)
不懂hash的话:https://www.cnblogs.com/ALINGMAOMAO/p/10345850.html 思路:对于一个大矩阵的每一个子矩阵都对应着一个hash值k, 当k出现2次以上 ...
- [luogu P1962] 斐波那契数列(带快速幂矩阵乘法模板)
题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数) 题目描述 请 ...
- LA 4670 (AC自动机 模板题) Dominating Patterns
AC自动机大名叫Aho-Corasick Automata,不知道的还以为是能自动AC的呢,虽然它确实能帮你AC一些题目.=_=|| AC自动机看了好几天了,作用就是多个模式串在文本串上的匹配. 因为 ...
- LA 3704 (矩阵快速幂 循环矩阵) Cellular Automaton
将这n个格子看做一个向量,每次操作都是一次线性组合,即vn+1 = Avn,所求答案为Akv0 A是一个n*n的矩阵,比如当n=5,d=1的时候: 不难发现,A是个循环矩阵,也就是将某一行所有元素统一 ...
随机推荐
- Session 快速开始 通过session的attribute通信
[web.xml] <session-config> <session-timeout>30</session-timeout> <cookie-config ...
- PHP中遍历二维数组—以不同形式的输出操作
<body> <?php //定义二维索引数组$arr = array( array("101","李军","男", ...
- Coursera, Deep Learning 5, Sequence Models, week3, Sequence models & Attention mechanism
Sequence to Sequence models basic sequence-to-sequence model: basic image-to-sequence or called imag ...
- scrapy和scrapy_redis入门
Scarp框架 需求 获取网页的url 下载网页内容(Downloader下载器) 定位元素位置, 获取特定的信息(Spiders 蜘蛛) 存储信息(ItemPipeline, 一条一条从管里走) 队 ...
- IActionResult的返回类型
ActionResult继承了IActionResult JsonResult.RedirectResult.FileResult.ViewResult.ContentResult均继承了Action ...
- Windows 7 SP1无人值守自动应答文件制作
使用U盘安装Windows系统时,很多人都会使用UltraISO工具来制作U盘启动盘,然后插入到电脑中加以安装.系统的安装过程中,需要一步一步手动选择或者输入配置,Windows是支持无人值守自动应答 ...
- Javascript - ExtJs - Itemselector
引入扩展文件 Extjs4.2根目录下: examples \ ux \ css \ images (这是选择按钮的图片资源) examples \ ux \ css \ ItemSelector.c ...
- 832B Petya and Exam
题意:给你两个串,第一个串里面的字母都是good 字母, 第二个串是模式串,里面除了字母还有?和*(只有一个) ?可以替换所有good字母, *可以替换所有坏字母和空格(可以是多个坏字母!!!这点卡了 ...
- CentOS 7 安装配置 MySQL
https://blog.imzhengfei.com/centos-7-an-zhuang-pei-zhi-mysql/ MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前 ...
- android页面渲染速度提升的常用方法
参考文档:http://blog.csdn.net/vector_yi/article/details/24402101 当activity中用到的布局较多较为复杂时,页面渲染就会变得复杂,现汇总以下 ...