Polyomino Composer
来源:互联网 发布:java高级工程师培训 编辑:程序博客网 时间:2024/05/17 01:53
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
100
思路:用小的图去填大的图。
#include<stdio.h>#include<string.h>#define MAX 25char poly1[MAX][MAX];char poly2[MAX][MAX];bool mark[MAX][MAX];struct Node{ int x; int y;}p1,p2;int main() { int n,m; while(~scanf("%d %d",&n,&m),(n||m)){memset(mark,false,sizeof(mark));int num1=0;int num2=0;bool flag=false; for(int i=0;i<n;i++){ scanf("%s",poly1[i]); for(int j=0;j<n;j++){ if(poly1[i][j]=='*') num1++; } } for(int i=0;i<m;i++){ scanf("%s",poly2[i]); for(int j=0;j<m;j++){if(poly2[i][j]=='*'){num2++;} } }//找p1 for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(poly1[j][i]=='*'){ p1.x=j; p1.y=i; flag=true; break; } } if(flag==true) break; }//找p2 flag=false; for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ if(poly2[j][i]=='*'){ p2.x=j; p2.y=i; flag=true; break; } } if(flag==true) break; } for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ if(poly2[i][j]=='*'){ mark[p1.x+i-p2.x][p1.y+j-p2.y]=true; } } }flag=false; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(poly1[j][i]=='*'&&mark[j][i]==false){ p1.x=j; p1.y=i; flag=true; break; } } if(flag==true){break;} } for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ if(poly2[i][j]=='*'&&mark[p1.x+i-p2.x][p1.y+j-p2.y]==false){ mark[p1.x+i-p2.x][p1.y+j-p2.y]=true; } } } int cnt=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(poly1[i][j]=='*'&&mark[i][j]==true){ cnt++; } } } if(cnt==num1&&num1==2*num2){ printf("1\n"); }else{ printf("0\n"); } } return 0;}/**4 3**..**....**..**....**.** 4 3.*..**..***.**..*..*..**.4 3.***.***.***........**.**4 2*...*......*...**.*. 3 2...**.**.******/
0 0
- Polyomino Composer
- UVA 12291 Polyomino Composer
- UVa 12291 Polyomino Composer
- UVA 12291 Polyomino Composer
- UVA-12291-Polyomino Composer
- Composer
- Composer
- composer
- composer
- Composer
- Composer
- composer
- composer
- composer
- composer
- composer
- composer
- composer
- 正在运行的android程序,再次点击程序图标避免再次重新启动程序解决办法
- 比较有意思的话
- HDUJ 2043 密码
- php安装模式cgi,fastcgi,php_mod比较
- Oracle表或者视图的行转列[练习]
- Polyomino Composer
- 黑马程序员-自己总结的winform常用控件(二)
- 迪杰斯克拉--双权值
- 在virtualBox中安装或者升级ubuntu后屏幕分辩率故障
- 游戏对象 (GameObject)
- UVa 1312 Cricket Field 解题报告(枚举 + 离散化)
- [leetcode] Partition List
- 内存泄漏问题
- plupload上传插件在SpringMVC中的整合(JAVA 版)【一】