首页 技术 正文
技术 2022年11月19日
0 收藏 483 点赞 4,594 浏览 1091 个字

题目链接

二维\(Hash\)类似二维前缀和,每一行看成一个\(h\)进制数,每一个以(1,1)为左上角的矩阵看成一个由每一行的\(Hash\)值组成的\(l\)进制数。

然后自己推推柿子就行。

#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
#define Open(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define h 1331
#define l 2333
int n, m, r, c, T;
map <unsigned long long, int> mp;
unsigned long long hs[1010][1010], ph[1010], pl[1010], xs[1010][1010];
char ch;
int main(){
Open("matrix"); ph[0] = pl[0] = 1;
scanf("%d%d%d%d", &n, &m, &r, &c);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j){
ch = getchar();
while(ch != '0' && ch != '1') ch = getchar();
hs[i][j] = hs[i][j - 1] * h + ch;
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
hs[i][j] += hs[i - 1][j] * l;
for(int i = 1; i <= m; ++i) ph[i] = ph[i - 1] * h;
for(int i = 1; i <= n; ++i) pl[i] = pl[i - 1] * l;
for(int i = r; i <= n; ++i)
for(int j = c; j <= m; ++j)
mp[hs[i][j] - hs[i - r][j] * pl[r] - hs[i][j - c] * ph[c] + hs[i - r][j - c] * pl[r] * ph[c]] = 1;
scanf("%d", &T);
while(T--){
for(int i = 1; i <= r; ++i)
for(int j = 1; j <= c; ++j)
xs[i][j] = 0;
for(int i = 1; i <= r; ++i)
for(int j = 1; j <= c; ++j){
ch = getchar();
while(ch != '0' && ch != '1') ch = getchar();
xs[i][j] = xs[i][j - 1] * h + ch;
}
for(int i = 1; i <= r; ++i)
for(int j = 1; j <= c; ++j)
xs[i][j] += xs[i - 1][j] * l;
printf("%d\n", mp[xs[r][c]]);
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,038
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,524
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,372
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,152
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,785
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,867