A - Polyomino Composer UVA - 12291

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 (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;
   }
}



转载于:https://www.cnblogs.com/da-mei/p/9053256.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值