본문 바로가기

Programming

알고스팟_게임판덮기(BOARDCOVER)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
#include<vector>
#include <string>
using namespace std;
 
int h, w;
int RP[4][3][2= {
    {{0,0},{1,0},{0,1}},
    {{0,0},{1,0},{1,1}},
    {{0,0},{0,1},{1,1}},
    {{0,0},{1,0},{1,-1}}
};
 
 
vector<string>setting(int type,int x, int y,vector<string> map) {
    vector<string> res = map;
    for (int i = 0; i < 3; i++) {
        int valueX = x + RP[type][i][0];
        int valueY = y + RP[type][i][1];
 
        if (valueX < 0 || valueY < 0 || map[valueX][valueY] == '#'return map;
        else res[valueX][valueY] = '#';
    }
    return res;
}
 
 
int solve(vector<string> m) {
    int x = -1;
    int y = -1;
    int valueX, valueY;
    int total = 0;
    vector<string> map = m;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (map[i][j] == '#'continue;
            else{
                x = i;
                y = j;
                break;
            }
        }
        if (x != -1)break;
    }
 
    if (x == -1) { return 1; }
    else{
        for (int type = 0; type <4 ; type++) {
            vector<string>setted = setting(type,x,y, map);
            //for (auto i = setted.begin(); i != setted.end(); ++i)cout << *i << endl;
            //cout << endl << endl;
            if (setted == map)continue;
            total +=solve(setted);
        }
    }
    return total;
}
 
void main() {
    int loop;
    int zero = 0;
    cin >> loop;
    while (loop--) {
        cin >> h >> w;
        vector<string>  map(h);
        for (int i = 0; i < h; i++cin >> map[i];
 
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (map[i][j] == '.') zero++;
            }
        }
        if (zero % 3 != 0)cout << 0 <<endl;
        else cout << solve(map) << endl;
        
    }
}
cs

https://www.algospot.com/judge/problem/read/BOARDCOVER

 

algospot.com :: BOARDCOVER

게임판 덮기 문제 정보 문제 H*W 크기의 게임판이 있습니다. 게임판은 검은 칸과 흰 칸으로 구성된 격자 모양을 하고 있는데 이 중 모든 흰 칸을 3칸짜리 L자 모양의 블록으로 덮고 싶습니다. 이 때 블록들은 자유롭게 회전해서 놓을 수 있지만, 서로 겹치거나, 검은 칸을 덮거나, 게임판 밖으로 나가서는 안 됩니다. 위 그림은 한 게임판과 이를 덮는 방법을 보여줍니다. 게임판이 주어질 때 이를 덮는 방법의 수를 계산하는 프로그램을 작성하세요. 입력 력의 첫

www.algospot.com

 

참고:

https://gist.github.com/fpdjsns/7b5a63f4e0ae9fa28b06ce4c7628f5e6

https://ddoublej.tistory.com/201

https://live.wbluke.com/blog/2019/01/03/6-2.BOARDCOVER/