zoukankan      html  css  js  c++  java
  • A

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



  • 相关阅读:
    FreeSWITCH第三方库(视频)的简单介绍(二)
    FreeSWITCH第三方库(音频)的简单介绍(一)
    libreoffice实现WORD文档转PDF文档
    Linux TOP命令详解
    java内存泄漏
    FreeSWITCH的传真发送
    CPU的一些参数和排名
    设计模式(九)访问者模式
    设计模式(八)状态模式
    使用PermissionsDispatcher轻松解决Android权限问题
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053256.html
Copyright © 2011-2022 走看看