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

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 }
时间: 2024-11-09 06:17:28

Polyomino Composer(UVA12291)的相关文章

View Composer Agent initialization error (16): Failed to activate software license (1026556)

1.       桌面发布过程中偶尔有些桌面池中的桌面提示无法访问代理,查看报错信息如下:View Composer Agent initialization error (16):Failed to activate software license (1026556). KB地址:https://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&externalId=1026556 主要意思是Windows 7系统激活的

composer.json:项目安装

基本用法 基本用法 安装 composer.json:项目安装 关于 require Key 包名称 包版本 下一个重要版本(波浪号运算符) 稳定性 安装依赖包 composer.lock - 锁文件 Packagist 自动加载 安装 安装 Composer,你只需要下载 composer.phar 可执行文件. curl -sS https://getcomposer.org/installer | php 详细请查看 简介 章节. 要检查 Composer 是否正常工作,只需要通过 php

Composer更新慢的终极解决方案

本文来自这里,纯粹为了备份 开始用Composer管理PHP的包依赖后,感觉神清气爽啊,不过问题很快就来了,更新速度太TMD的慢了啊有木有,基本到了没法用的地步.怎么办?那就是VPN啦.买个VPN,问题一下解决了.但是,公司的路由器是关闭VPN相关的端口的,只开放个80,8000等端口走走HTTP协议.怎么办?程序员们都知道,有个好用又免费的神器,就是GoAgent. 让命令行使用代理 怎么安装GoAgent就不说啦,网上教程一大堆,自己找去.安装还后,各种浏览器都可以开心的用上代理啦,从此Gi

Composer 笔记(PHPconf 台湾)

演讲人:by 大泽木小铁@KKBox composer解决问题的场景: 方便接手项目的新人知道项目依赖于哪些类库(比如xml,log) 其他语言的套件管理系统: node.js (npm), Ruby(gem), PHP (PEAR -> Pyrus即PEAR2 -> composer) Comoser的优点: - 可以针对项目,而非针对整个系统 - 可以检查执行环境 - 套件审核机制方便 - 设定文档编写简单,不需要用xml,而是用JSON - 不需要用官方的套件库 - 流行 - 仿造npm

用composer装oauth2-server-php v0.9(bshaffer)

从官网下载composer https://getcomposer.org/ composer是跨平台的, 这里只介绍windows使用composer 下载好了后, 进行安装. 可以选择 "Install Shell Menus", 这将会在右键菜单里面增加composer的快捷入口. composer会自动找到php.exe的位置. 也可以自定义php的位置. 下载composer.phar 该死的"墙", 连接上VPN. 我的php 5.3.3 确实够老的.

在windows下使用Composer安装ZendFramework2

首先安装Composer,可以去 这里 下载,或者到 这个中文站点 下载. 然后调出 开始->运行->cmd 进去, 然后运行下面的命令: composer create-project -sdev --repository-url="https://packages.zendframework.com" zendframework/skeleton-application path/to/install path/to/install 表示你自己的项目目录

wamp2.4+composer+rabbitmq环境部署-176

version wamp 2.4 1.打开openssl 分别更改php.ini的文件配置 E:\wamp\bin\apache\Apache2.4.4\bin\php.ini E:\wamp\bin\apache\Apache2.4.4\bin\php.ini php.ini的功能打开 extension=php_openssl.dll 2.Composer下载 https://getcomposer.org/Composer-Setup.exe 下载完成直接点下一步图型安装-- 3.php-

Simulation.Lab.Software.SimLab.Composer.2015.v6.1.MACOSX 1CD

CA Spectrum Linux VM 10.01.00.00.103 Linux 2DVD  Tahoe Design HYDROFLO v3.0.0.4 1CD  CA Spectrum Windows VM 10.01.00.00.103 Win64 2DVD  Delcam Exchange 2016 R2 CR 8.3.1005 Win64 1CD  Delcam PowerSHAPE 2016 SP2 Update only 1CD  ESI Group VA One 2015.0

windows安装composer

下载安装 https://getcomposer.org/Composer-Setup.exe   我安装到了c:/composer,没有设置环境变量. 以下检测是否安装成功. cmd 里执行安装easywechat:  e:\php\thinkcmf-master\thinkcmf5\simplewind\vendor\overtrue\wechat>d:\phpStudy\php55\php c:/composer/composer.phar install 提示如下错误:貌似是版本错误.