to edge.
– Wikipedia
There will be at most 20 test cases. Each test case begins with two integers n and m (1 ≤ m ≤ n ≤ 10)
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<iostream> #include<string.h> #include<math.h> #include<algorithm> #include<queue> #include<string> #include<map> #include<stack> #define maxn 505 #define inf 0x3f3f3f3f #define ll long long using namespace std; string s[maxn],t[maxn]; int x[maxn],y[maxn]; int l,n,m; bool judge1(int a,int b){ if(a<0||a>=n||b<0||b>=n||s[a][b]!='*') return false; else return true; } bool judge(int a,int b){ for(int i=0;i<l;i++){ if(!judge1(a+x[i],b+y[i]))return false; } for(int i=0;i<l;i++){ s[a+x[i]][b+y[i]]='.'; } return true; } int main(){ while(~scanf("%d%d",&n,&m)&&n|m){ memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); for(int i=0;i<n;i++)cin>>s[i]; for(int i=0;i<m;i++)cin>>t[i]; int fx=-1,fy=-1;l=0; for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ if(t[i][j]=='*'){ if(fx==-1&&fy==-1){fx=i;fy=j;} else{x[l]=(i-fx);y[l]=(j-fy);l++;} } } } // for(int i=0;i<l;i++){ // cout<<x[i]<<" "<<y[i]<<endl; // } int flag=0,ans=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(s[i][j]=='*'){ if(judge(i,j))ans++;//cout<<ans<<endl; if(ans==2){flag=1;cout<<1<<endl;break;} } }if(flag==1)break; } if(flag==0)cout<<0<<endl; } }