• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 12291 - Polyomino Composer

你为何这么叼!

Polyomino Composer 

 Time limit: 1.000 seconds

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

 


The Seventh Hunan Collegiate Programming Contest
Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 #define maxn 61
 6 int n,m,k;
 7 char s[maxn][maxn];
 8 char ts[maxn][maxn];
 9 int a[maxn][maxn];
10 int b[maxn][maxn];
11 int c[maxn][maxn];
12 int main(){
13     int x1,x2,y1,y2,tx1,tx2,ty1,ty2,sx1,sx2,sy1,sy2;
14     while(scanf("%d%d",&n,&m)&&(n+m)){
15         int flag=1;
16         memset(a,0,sizeof a);
17         memset(b,0,sizeof b);
18         memset(c,0,sizeof c);
19         for(int i=0;i<n;i++){
20             scanf("%s",s[i]);
21             for(int j=0;j<n;j++)
22                 if(s[i][j]=='*')a[i+20][j+20]=1;
23         }
24         for(int i=0;i<m;i++){
25             scanf("%s",ts[i]);
26             for(int j=0;j<m;j++)
27                 if(ts[i][j]=='*')b[i][j]=1;
28         }
29         for(int i=20;i<20+n;i++)
30             for(int j=20;j<20+n;j++)
31                 if(a[i][j]==1){x1=i;y1=j;i=100;break;}
32         for(int i=0;i<m;i++)
33             for(int j=0;j<m;j++)
34                 if(b[i][j]==1){tx1=i;ty1=j;i=100;break;}
35         for(int i=n-1+20;i>=20;i--)
36             for(int j=n-1+20;j>=20;j--)
37                 if(a[i][j]==1){x2=i;y2=j;i=-1;break;}
38         for(int i=m-1;i>=0;i--)
39             for(int j=m-1;j>=0;j--)
40                 if(b[i][j]==1){tx2=i;ty2=j;i=-1;break;}
41         sx1=x1-tx1;sy1=y1-ty1;
42         for(int i=sx1;i<sx1+m;i++)
43             for(int j=sy1;j<sy1+m;j++)
44                 c[i][j]+=b[i-sx1][j-sy1];
45         sx2=x2+m-tx2;sy2=y2+m-ty2;
46         for(int i=sx2-1;i>=sx2-m;i--)
47             for(int j=sy2-1;j>=sy2-m;j--)
48                 c[i][j]+=b[i+m-sx2][j+m-sy2];
49         for(int i=20;i<20+n;i++)
50             for(int j=20;j<20+n;j++)
51                 if(a[i][j]!=c[i][j]){flag=0;i=100;break;}
52         if(flag)puts("1");else puts("0");
53     }
54     return 0;
55 }
View Code

 

posted @ 2013-10-10 12:02  HaibaraAi  阅读(185)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3