[bzoj2462] [BeiJing2011]矩阵模板

  二维的hash。。

  注意n的范围是1000........

  真相似乎是全部输出1就行了233

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #define ull unsigned long long
 5 using namespace std;
 6 const int maxn=1013;
 7 const int modd=23333333;
 8 ull pre[maxn][maxn],v[maxn][maxn],jc[maxn];
 9 int n,m,a,b,q;
10 char s[maxn];
11 bool u[23333333];
12 
13 int main(){
14     register int i,j,k;
15     scanf("%d%d%d%d",&n,&m,&a,&b);
16     for(i=jc[0]=1;i<=m;i++)jc[i]=jc[i-1]*233;
17     for(i=1;i<=n;i++){
18         scanf("%s",s+1);
19         for(j=1;j<=m;j++)pre[i][j]=pre[i][j-1]*233+s[j];
20         if(i==a)
21             for(j=b;j<=m;j++)
22             for(k=1;k<=i;k++)v[i][j]=v[i][j]*233+pre[k][j]-pre[k][j-b]*jc[b];
23         else if(i>a)
24             for(j=b;j<=m;j++)v[i][j]=v[i-1][j]*233+pre[i][j]-pre[i][j-b]*jc[b]-(pre[i-a][j]-pre[i-a][j-b]*jc[b])*jc[a];
25     }
26     for(i=1;i<=n;i++)for(j=1;j<=m;j++)u[v[i][j]%modd]=1;
27     scanf("%d",&q);
28     while(q--){
29         ull now=0,now1;
30         for(i=1;i<=a;i++){
31             scanf("%s",s+1);
32             for(now1=0,j=1;j<=b;j++)now1=now1*233+s[j];
33             now=now*233+now1;
34         }
35         bool flag=u[now%modd];
36         //for(i=a;i<=n&&!flag;i++)for(j=b;j<=m;j++)if(v[i][j]==now){flag=1;break;}
37         puts(flag?"1":"0");
38     }
39     return 0;
40 }
View Code

 

posted @ 2016-03-21 14:13  czllgzmzl  阅读(330)  评论(0编辑  收藏  举报