Polyomino Composer(UVA12291)
2016-07-10 08:23
246 查看
Description
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).
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.
思路:暴力枚举下即可;
Polyomino Composer |
A polyomino is a plane geometric figure formed by joining one or more equal squares edge to edge.
[align=RIGHT]- Wikipedia[/align]
[align=RIGHT]- Wikipedia[/align]
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 ( 1m
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<algorithm> #include<iostream> #include<queue> #include<math.h> #include<stdlib.h> #include<string.h> char ans[20][20]; char bns[20][20]; char ask[20][20]; char ck[20][20]; bool flag=0; bool tie(int n,int m,int xx,int yy,int mxx,int myy)//先贴第一个 { int i,j; for(i=n; i<=xx; i++) { for(j=m; j<=yy; j++) { int p=i-n; int q=j-m; ck[i][j]=bns[mxx+p][myy+q]; } } } bool check(int n,int m,int xx,int yy,int mxx,int myy,int t)//贴第二个并判断与要求的图形是否相同 { int i,j; for(i=n; i<=xx; i++) { for(j=n; j<=yy; j++) { int p=i-n; int q=j-m; if(ask[i][j]=='.'&&bns[mxx+p][myy+q]=='*') { ask[i][j]='*'; } else if(ask[i][j]=='*'&&bns[mxx+p][myy+q]=='*') { return false; } } } for(i=0;i<t;i++) { for(j=0;j<t;j++) { if(ask[i][j]!=ans[i][j]) return false; } } return true; } int main(void) { int i,j,k; int n,m; while(scanf("%d %d",&n,&m),n!=0&&m!=0) { flag=0; memset(ask,0,sizeof(ask)); for(i=0; i<n; i++) { scanf("%s",ans[i]); } for(i=0; i<m; i++) { scanf("%s",bns[i]); } int x,y; int x1=0; int x2=m; int y1=0; int y2=m; for(i=0; i<m; i++) { for(j=0; j<m; j++) { if(bns[i][j]=='*') { if(i>x1) x1=i; if(j>y1) y1=j; if(i<x2) x2=i; if(j<y2) y2=j; } } } int xx2=x1-x2; int yy2=y1-y2; for(i=0; i<n; i++) { for(j=0; j<n; j++) { for(int s=0; s<n; s++) { for(int uu=0; uu<n; uu++) { ck[s][uu]='.'; } } if(i+xx2>n-1||j+yy2>n-1) continue; else { tie(i,j,i+xx2,j+yy2,x2,y2); for(x=0; x<n; x++) { for(y=0; y<n; y++) { for(int s=0; s<n; s++) { for(int uu=0; uu<n; uu++) { ask[s][uu]=ck[s][uu]; } } if(x+xx2>n-1||y+yy2>n-1) continue; else { flag=check(x,y,x+xx2,y+yy2,x2,y2,n); if(flag) { break; } } }if(flag)break; } } if(flag)break; } if(flag)break; } if(flag)printf("1\n"); else printf("0\n"); } return 0; }
相关文章推荐
- 启动mysql服务
- 哈希表(三)
- 用js怎么取table中的tr标签--这是一个陷阱
- windows10安装Oracle提示错误-INS-13001环境不满足最低要求
- Android布局优化之ViewStub、include、merge使用与源码分析
- Java中Map根据键值(key)或者值(value)进行排序实现
- Uva11396 Claw Decomposition(爪分解)
- HDU2051 Bitset
- Android 如何直播RTMP流
- 15、JS回调函数与call函数
- java如何对map进行排序详解(map集合的使用)
- StrPCopy与StrPas功能正好相反,作用是与C语言字符串和Delphi的String相互转化
- C# mouse keyboard monitor
- 【算法-2】判断字符串是否为回纹串
- linq按条件sum
- Comparable的使用
- Docker中部署Kubernetes
- Contiki开发3:调试平台与Debug系统
- JavaScript生态圈现状:初学者地图
- Linux运维经验分享与思路