题意:给定一个01矩阵。T个询问,每次询问大矩阵中是否存在这个特定的小矩阵。

 /*
64位的位运算!!!
题意:
给定一个01矩阵。T个询问,每次询问大矩阵中是否存在这个特定的小矩阵。
(64位记录状态!!!)
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int maxm = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; char mat[ maxn ][ maxn ];
char tmp[ maxm ][ maxm ];
int64 A[ maxn ][ maxn ];
int64 AA[ maxm ];
int64 sum[ maxn ][ maxn ]; void init( int n,int m,int p,int q ){
for( int i=;i<=m;i++ )
sum[][i] = ;
for( int i=;i<=n;i++ )
sum[i][] = ;
for( int i=;i<=n;i++ ){
for( int j=;j<=m;j++ ){
sum[ i ][ j ] = sum[i][j-]+sum[i-][j]-sum[i-][j-];
if( mat[i][j]=='*' )
sum[i][j] ++;
}
}
memset( A,,sizeof( A ) );
for( int i=;i<=n;i++ ){
for( int j=;j<=q;j++ ){
if( mat[i][j]=='*' )
A[i][q] |= ((1LL)<<(j-));
}
}
for( int i=;i<=n;i++ ){
for( int j=q+;j<=m;j++ ){
if( mat[i][j-q]=='*' ) A[i][j] = A[i][j-]-(1LL);
else A[i][j] = A[i][j-];
A[i][j] = A[i][j]>>(1LL);
if( mat[i][j]=='*' )
A[i][j] |= ((1LL)<<(q-));
}
}
} void GetBinary( int p,int q ){
for( int i=;i<=p;i++ ){
AA[ i ] = ;
for( int j=;j<=q;j++ ){
if( tmp[i][j]=='*' )
AA[ i ] |= ((1LL)<<(j-));
}
}
} int Judge( int n,int m,int p,int q,int64 cnt ){
for( int i=;i+p-<=n;i++ ){
if( sum[n][m]-sum[i-][m]<cnt ) break;
for( int j=q;j<=m;j++ ){
bool f = true;
for( int k=;k<=p;k++ ){
if( AA[k]!=A[i+k-][j] ){
f = false;
break;
}
}
if( f==true ) return ;
}
}
return ;
} int main(){
int n,m,t,p,q;
int Case = ;
while( scanf("%d%d%d%d%d",&n,&m,&t,&p,&q)== ){
if( n+m+t+p+q== ) break;
for( int i=;i<=n;i++ ){
scanf("%s",mat[i]+);
}
init( n,m,p,q );
int ans = ;
while( t-- ){
int64 cnt = ;
for( int i=;i<=p;i++ ){
scanf("%s",tmp[i]+);
for( int j=;j<=q;j++ ){
if( tmp[i][j]=='*' )
cnt++;
}
}
GetBinary( p,q );
ans += Judge( n,m,p,q,cnt );
}
printf("Case %d: ",Case++);
printf("%d\n",ans);
}
return ;
}
05-11 13:21