A polyomino is a plane geometric figure formed by joining one or more equal squares edge to edge.- Wikipedia
Given a large polyomino and a small polyomino, your task is to determine whether you can compose the large one with two copies of the small one. The polyominoes can be translated, but not flipped or rotated. The two pieces should not overlap. The leftmost picture below is a correct way of composing the large polyomino, but the right two pictures are not. In the middle picture, one of the pieces was rotated. In the rightmost picture, both pieces are exactly identical, but they're both rotated from the original piece (shown in the lower-right part of the picture).
Input
There will be at most 20 test cases. Each test case begins with two integers n and m ( 1mn10 ) in a single line. The next n lines describe the large polyomino. Each of these lines contains exactly n characters in ` * ',` . '. A ` * ' indicates an existing square, and a ` . ' indicates an empty square. The next m lines describe the small polyomino, in the same format. These characters are guaranteed to form valid polyominoes (note that a polyomino contains at least one existing square). The input terminates with n = m = 0 , which should not be processed.
Output
For each case, print ` 1 ' if the corresponding composing is possible, print ` 0 ' otherwise.
Sample Input
4 3 .**. **** .**. .... **. .** ... 3 3 *** *.* *** *.. *.. **. 4 2 **** .... .... .... *. *. 0 0
Sample Output
1 0 0
思路:用小的图去填大的图。
#include<stdio.h>
#include<string.h>
#define MAX 25
char poly1[MAX][MAX];
char poly2[MAX][MAX];
bool mark[MAX][MAX];
struct Node{
int x;
int y;
}p1,p2;
int main() {
int n,m;
while(~scanf("%d %d",&n,&m),(n||m)){
memset(mark,false,sizeof(mark));
int num1=0;
int num2=0;
bool flag=false;
for(int i=0;i<n;i++){
scanf("%s",poly1[i]);
for(int j=0;j<n;j++){
if(poly1[i][j]=='*') num1++;
}
}
for(int i=0;i<m;i++){
scanf("%s",poly2[i]);
for(int j=0;j<m;j++){
if(poly2[i][j]=='*'){
num2++;
}
}
}//找p1
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(poly1[j][i]=='*'){
p1.x=j;
p1.y=i;
flag=true;
break;
}
}
if(flag==true) break;
}//找p2
flag=false;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(poly2[j][i]=='*'){
p2.x=j;
p2.y=i;
flag=true;
break;
}
}
if(flag==true) break;
}
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(poly2[i][j]=='*'){
mark[p1.x+i-p2.x][p1.y+j-p2.y]=true;
}
}
}
flag=false;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(poly1[j][i]=='*'&&mark[j][i]==false){
p1.x=j;
p1.y=i;
flag=true;
break;
}
}
if(flag==true){
break;
}
}
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(poly2[i][j]=='*'&&mark[p1.x+i-p2.x][p1.y+j-p2.y]==false){
mark[p1.x+i-p2.x][p1.y+j-p2.y]=true;
}
}
}
int cnt=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(poly1[i][j]=='*'&&mark[i][j]==true){
cnt++;
}
}
}
if(cnt==num1&&num1==2*num2){
printf("1\n");
}else{
printf("0\n");
}
}
return 0;
}
/**
4 3
**..
**..
..**
..**
...
.**
.**
4 3
.*..
**..
***.
**..
*..
*..
**.
4 3
.***
.***
.***
....
...
.**
.**
4 2
*...
*...
...*
...*
*.
*.
3 2
...
**.
**.
**
**
**/