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

Input

There will be at most 20 test cases. Each test case begins with two integers n and m ( 1mn10) 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\n");
140 else printf("0\n");
141 }
142 return 0;
143 }

Polyomino Composer(UVA12291)的更多相关文章

  1. Laravel Composer and ServiceProvider

    Composer and: 创建自定义类库时,按命名空间把文件夹结构组织好 composer.json>autoload>classmap>psr-4 composer dump-a ...

  2. 基于Composer Player 模型加载和相关属性设置

    主要是基于达索软件Composer Player.的基础上做些二次开发. public class ComposerToolBarSetting { public bool AntiAliasingO ...

  3. Composer概述及其自动加载探秘

    composer概述 一开始,最吸引我的当属 Composer 了,因为之前从没用过 Composer . Composer 是PHP中用来管理依赖关系的工具,你只需在自己的项目中声明所依赖的外部工具 ...

  4. composer 出现 configuration does not allow connection to http.......

    出现这样的问题是,镜像使用的是http,而原地址是需要https,所以配置下关掉https就好了. 我们来个全局设置的方法: composer config -g secure-http false ...

  5. 在linux上如何通过composer安装yii

      Composer可以理解成一个依赖管理工具 它能解决以下问题 a) 你有一个项目依赖于若干个库. b) 其中一些库依赖于其他库. c) 你声明你所依赖的东西. d) Composer 会找出哪个版 ...

  6. composer

    composer 是PHP框架的包安装工具,类似于bower ,npm.bundler. 是命令行工具,没有图形界面. 系统要求 运行 Composer 需要 PHP + 以上版本.一些敏感的 PHP ...

  7. composer 报错:Your requirements could not be resolved to an installable set of packages 解决方法

    composer 报错: - Your requirements could not be resolved to an installable set of packages xxxxxxxxxxx ...

  8. composer 使用笔记

    使用composer 更新项目比如: composer create-project topthink/think wwwroot dev-master --prefer-dist提示openssl异 ...

  9. mac composer 安装

    在命令行执行 curl -sS https://getcomposer.org/installer | php 如果没安装 curl 执行以下代码 php -r "readfile('htt ...

随机推荐

  1. adblock plus-看下图你就懂

  2. 以DevExpress开发的WinFrom程序的多语言功能的实现

    以DevExpress开发的WinFrom程序的多语言功能的实现 写在前面: 多语言切换功能在Winform程序中是经常遇到的需求,尤其是需要给国外客户使用的情况下,多语言功能是必不可少的.前一段时间 ...

  3. 笔记Mysql(1)

    客户端的登录命令 查看版本 查看设置(数据库的基本设置信息) 查看时间 查看链接数 查看超时的关键字 创建数据库 查看已有数据库 进入数据库,查询链接到的数据库 查询数据目录 创建表 查看表

  4. 为构建大型复杂系统而生的微服务框架 Erda Infra

    作者|宋瑞国(尘醉) 来源|尔达 Erda 公众号 ​ 导读:Erda Infra 微服务框架是从 Erda 项目演进而来,并且完全开源.Erda 基于 Erda Infra 框架完成了大型复杂项目的 ...

  5. Lombok安装及Spring Boot集成Lombok

    文章目录 Lombok有什么用 使用Lombok时需要注意的点 Lombok的安装 spring boot集成Lombok Lombok常用注解 @NonNull @Cleanup @Getter/@ ...

  6. OC-代理,字符串

    总结 编号 标题 内容 一 protocol protocol 基本概念/语法格式/protocol和继承区别/使用注意/基协议/@required和@optional关键字/类型限制 二 代理设计模 ...

  7. maven常用Java配置

    maven国内镜像 ------------------------------------------------------------------------------------------ ...

  8. Hystrix断路器中的服务熔断与服务降级

    一.Hystrix断路器 微服务架构特点就是多服务,多数据源,支撑系统应用.这样导致微服务之间存在依赖关系.如果其中一个服务故障,可能导致系统宕机,这就是所谓的雪崩效应. 1.为什么需要断路器 服务雪 ...

  9. 【Matlab】CFAR/phased.CFARDetector2D

    | CFAR学习进行时ing... | CFAR原理.参数 检测阈值\(T = αP_n\) \(P_n\)是噪声功率估计,\(α\)是比例因子 训练单元:训练噪声,估计\(P_n = \frac{1 ...

  10. RDS备份到OSS增量+全量

    一.前言 阿里云的RDS备份是占用使用量的,你购买200G那备份使用量是100G左右,导致备份一般也就存半个月,2个全备份. 那半个月后之前的也就删除了,如果要持续保留更久将花费不少的金钱.所以这里用 ...