zoukankan      html  css  js  c++  java
  • Polyomino Composer(UVA12291)

    Description

      Polyomino Composer 
    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).

    epsfbox{p12291.eps}

    Input 

    There will be at most 20 test cases. Each test case begins with two integers n and m ( 1$ le$m$ le$n$ le$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
    

     思路:暴力枚举下即可;

      1 #include<stdio.h>
      2 #include<algorithm>
      3 #include<iostream>
      4 #include<queue>
      5 #include<math.h>
      6 #include<stdlib.h>
      7 #include<string.h>
      8 char ans[20][20];
      9 char bns[20][20];
     10 char ask[20][20];
     11 char ck[20][20];
     12 bool flag=0;
     13 bool tie(int n,int m,int xx,int yy,int mxx,int myy)//先贴第一个
     14 {
     15     int i,j;
     16     for(i=n; i<=xx; i++)
     17     {
     18         for(j=m; j<=yy; j++)
     19         {
     20             int p=i-n;
     21             int q=j-m;
     22             ck[i][j]=bns[mxx+p][myy+q];
     23         }
     24     }
     25 }
     26 bool check(int n,int m,int xx,int yy,int mxx,int myy,int t)//贴第二个并判断与要求的图形是否相同
     27 {   int i,j;
     28     for(i=n; i<=xx; i++)
     29     {
     30         for(j=n; j<=yy; j++)
     31         {
     32             int p=i-n;
     33             int q=j-m;
     34             if(ask[i][j]=='.'&&bns[mxx+p][myy+q]=='*')
     35             {
     36                 ask[i][j]='*';
     37             }
     38             else if(ask[i][j]=='*'&&bns[mxx+p][myy+q]=='*')
     39             {
     40                 return false;
     41             }
     42         }
     43     }
     44     for(i=0;i<t;i++)
     45     {
     46         for(j=0;j<t;j++)
     47         {
     48             if(ask[i][j]!=ans[i][j])
     49                 return false;
     50         }
     51     }
     52     return true;
     53 }
     54 
     55 int main(void)
     56 {
     57     int i,j,k;
     58     int n,m;
     59     while(scanf("%d %d",&n,&m),n!=0&&m!=0)
     60     {
     61         flag=0;
     62         memset(ask,0,sizeof(ask));
     63         for(i=0; i<n; i++)
     64         {
     65             scanf("%s",ans[i]);
     66         }
     67         for(i=0; i<m; i++)
     68         {
     69             scanf("%s",bns[i]);
     70         }
     71         int x,y;
     72         int x1=0;
     73         int x2=m;
     74         int y1=0;
     75         int y2=m;
     76         for(i=0; i<m; i++)
     77         {
     78             for(j=0; j<m; j++)
     79             {
     80                 if(bns[i][j]=='*')
     81                 {
     82                     if(i>x1)
     83                         x1=i;
     84                     if(j>y1)
     85                         y1=j;
     86                     if(i<x2)
     87                         x2=i;
     88                     if(j<y2)
     89                         y2=j;
     90                 }
     91             }
     92         }
     93         int xx2=x1-x2;
     94         int yy2=y1-y2;
     95         for(i=0; i<n; i++)
     96         {
     97             for(j=0; j<n; j++)
     98             {
     99                 for(int s=0; s<n; s++)
    100                 {
    101                     for(int uu=0; uu<n; uu++)
    102                     {
    103                         ck[s][uu]='.';
    104                     }
    105                 }
    106                 if(i+xx2>n-1||j+yy2>n-1)
    107                     continue;
    108                 else
    109                 {
    110                     tie(i,j,i+xx2,j+yy2,x2,y2);
    111                     for(x=0; x<n; x++)
    112                     {
    113                         for(y=0; y<n; y++)
    114                         {
    115                             for(int s=0; s<n; s++)
    116                             {
    117                                 for(int uu=0; uu<n; uu++)
    118                                 {
    119                                     ask[s][uu]=ck[s][uu];
    120                                 }
    121                             }
    122                             if(x+xx2>n-1||y+yy2>n-1)
    123                                 continue;
    124                             else
    125                             {
    126                                 flag=check(x,y,x+xx2,y+yy2,x2,y2,n);
    127                                 if(flag)
    128                                 {
    129                                     break;
    130                                 }
    131                             }
    132                         }if(flag)break;
    133                     }
    134                 }
    135                 if(flag)break;
    136             }
    137             if(flag)break;
    138         }
    139         if(flag)printf("1
    ");
    140         else printf("0
    ");
    141     }
    142     return 0;
    143 }
    油!油!you@
  • 相关阅读:
    User Get 'Access Denied' with Excel Service WebPart
    How To Search and Restore files from Site Collection Recycle Bin
    How To Collect ULS Log from SharePoint Farm
    How To Restart timer service on all servers in farm
    How to Operate SharePoint User Alerts with PowerShell
    How to get Timer Job History
    Synchronization Service Manager
    SharePoint 2007 Full Text Searching PowerShell and CS file content with SharePoint Search
    0x80040E14 Caused by Max Url Length bug
    SharePoint 2007 User Re-created in AD with new SID issue on MySite
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5657077.html
Copyright © 2011-2022 走看看