Description
A n*m of checkered paper, some grids need to be printed in black, the remaining squares need to preserve white.
You have a a*b seal, and some of the lattice is raised (it will be stained with ink). You need to decide whether you can use this seal to print out the pattern on the paper. The following requirements must be met in the process of printing:
(1) The seal cannot be rotated.
(2) Do not print ink to the outside of the paper.
(3) The same lattice on the paper can not be printed multiple times.
Input
The first line, an integer q (1<=q<=10), indicates the number of test points.
Next, Q test points, each of the test points:
The first line consists of 4 integers n,m,a,b (1<=n,m,a,b<=1000).
The next n lines, m characters per line, describe the pattern on the paper. ‘.‘ Indicates white, ' x ' indicates the need to dye black.
Next a line, B characters per line, describes the seal. ‘.‘ The ink is not stained, ' x ' indicates a dip in ink.
Output
For each test point, the output is tak (yes) or NIE (no).
Sample Input
2
3 4 4 2
Xx..
. xx.
Xx..
X.
. x
X.
..
2 2 2 2
Xx
Xx
. x
X.
Sample Output
Sa
NIE
HINT
Source
Acknowledgement JCVB
Idea: Because the point on the left is definitely the corresponding one, so every time we look for the point on the left, we cover the point of the seal off the analog side.
#include <cstdio>
#include <string.h>
#include <algorithm>
#define MAXN 1009
using namespace Std;
struct T
{int x;int y;} Z[MAXN*MAXN];
int h,a,b,c,d,ma[maxn][maxn],t;
Char CH[MAXN];
int main () {
scanf ("%d", &t);
while (t--) {
scanf ("%d%d%d%d", &a,&b,&c,&d);
for (int i=1;i<=a;i++) {
scanf ("%s", ch+1);
for (int j=1;j<=b;j++) if (ch[j]== '. ') Ma[i][j]=1;else ma[i][j]=2;
}
int flag=h=0;
for (int i=1;i<=c;i++) {
scanf ("%s", ch+1);
for (int j=1;j<=d;j++)
if (ch[j]== ' x ' && flag==0) flag=1,z[++h].x=i,z[h].y=j;
else if (ch[j]== ' x ') z[++h].x=i-z[1].x,z[h].y=j-z[1].y;
}flag=0;
for (int i=1;i<=a;i++) {
for (int j=1;j<=b;j++) {
if (ma[i][j]==2) {ma[i][j]=1;
for (int k=2;k<=h;k++) {
if (x>=1&&y>=1&&ma[i+z[k].x][j+z[k].y]==2) ma[i+z[k].x][j+z[k].y]=1;
Else{flag=1;break;}
}if (flag==1) break;
}
}if (flag==1) break;
}
if (flag==0) printf ("tak\n"), Else printf ("nie\n");
for (int i=1;i<=a;i++) for (int j=1;j<=b;j++) ma[i][j]=0;
}
return 0;
}
Bzoj 3750: [Poi2015]piecz?? Simulation