[UVA] 12291 - Polyomino Composer@Morris' Blog|PChome Online 人新台
2013-07-18 10:47:17| 人1,032| 回0 | 上一篇 | 下一篇

[UVA] 12291 - Polyomino Composer

0 收藏 0 0 站台


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

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

目描述:

不旋及翻,一形有有可能被小形拼出,而且不互相重。

目解法:

由於定的小示都是正方形,且是通,但是拼的候可能有多的小示超界。

先抓一小示的非空,然後去大示的其中一,接著去它。

接著再抓一被使用的,再第二次,中查是否有碰撞。


#include <stdio.h>
#include <string.h>
char g1[50][50], g2[50][50];
int used[15][15], used2[15][15], err;
int n, m;
void dfs(int x, int y, int vx, int vy) {
    if(x < 0 || y < 0 || x >= m || y >= m)
        return;
    if(err || g2[x][y] == '.' || used2[x][y])
        return;
    if(vx < 0 || vy < 0 || vx >= n || vy >= n || g1[vx][vy] == '.' || used[vx][vy] == 1)
        err = 1;
    used2[x][y] = 1;
    used[vx][vy] = 1;
    dfs(x+1, y, vx+1, vy);
    dfs(x-1, y, vx-1, vy);
    dfs(x, y+1, vx, vy+1);
    dfs(x, y-1, vx, vy-1);
}
int main() {
    int i, j, k, p, q, r, a, b, c;
    while(scanf("%d %d", &n, &m) == 2) {
        if(n == 0 && m == 0)
            break;
        for(i = 0; i < n; i++)
            scanf("%s", &g1[i]);
        for(i = 0; i < m; i++)
            scanf("%s", &g2[i]);
        int px, py;
        for(i = 0; i < m; i++) {
            for(j = 0; j < m; j++) {
                if(g2[i][j] == '*') {
                    px = i, py = j;
                    i = m, j = m;
                }
            }
        }
        int ret = 0;
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                if(g1[i][j] == '*') {
                    memset(used, 0, sizeof(used));
                    memset(used2, 0, sizeof(used2));
                    err = 0;
                    dfs(px, py, i, j);
                    if(err) continue;
                    for(p = 0; p < n; p++) {
                        for(q = 0; q < n; q++) {
                            if(g1[p][q] == '.' || used[p][q])
                                continue;
                            memset(used2, 0, sizeof(used2));
                            err = 0;
                            dfs(px, py, p, q);
                            if(err) continue;
                            ret = 1;
                            p = n, q = n, i = n, j = n;
                        }
                    }
                }
            }
        }
        printf("%d\n", ret);
    }
    return 0;
}

台: Morris
人(1,032) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA] 790 - Head Judge Headache
此分上一篇:[UVA][生命] 12187 - Brothers

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86