Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

혼종 꼬지마루

[백준] 3967 - 매직스타 본문

Algorithms/DFS

[백준] 3967 - 매직스타

꼬지마루 2018. 9. 14. 22:39

문제를 잘못 이해해서 한번 틀린 문제...


무작위가 아닌, '한줄로 이어 붙였을 때 사전 순서'라는 점에 초점을 맞추면 그다음 부터는 쉬워진다


입력을 받으며 x인 부분은 구조체 배열로 그 위치를 담아주고, A~L인 부분은 check해준다.


그다음 부터는 한 위치씩, 모든 경우의 수를 넣어주고 끝까지 넣고 난 후 조건에 맞으면 flag를 달아주고 출력하면 끝


조건을 검사하는 부분에서 따로 머리써서 단순화 시키기 보다는 그냥 무식하게 인덱스로 다 찾아서 더해줬다...ㅎ


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
#include <iostream>
#define MX 60
using namespace std;
 
struct KKK {
    int x, y;
}arr[15];
 
char map[6][10];
int check[MX / 2];
int flag, cnt;
 
void dfs(int d, int pos)
{
    if (d == cnt)
    {
        if (map[0][4+ map[1][3+ map[2][2+ map[3][1- * 'A' + != 26return;
        if (map[0][4+ map[1][5+ map[2][6+ map[3][7- * 'A' + != 26return;
        if (map[3][1+ map[3][3+ map[3][5+ map[3][7- * 'A' + != 26return;
        if (map[1][1+ map[1][3+ map[1][5+ map[1][7- * 'A' + != 26return;
        if (map[1][1+ map[2][2+ map[3][3+ map[4][4- * 'A' + != 26return;
        if (map[1][7+ map[2][6+ map[3][5+ map[4][4- * 'A' + != 26return;
        flag = 1;
        return;
    }
    for (int i = 0; i < 12; i++)
    {
        if (check[i]) continue;
        check[i] = 1;
        map[arr[pos].y][arr[pos].x] = i + 'A';
        dfs(d + 1, pos + 1);
        if (flag) return;
        map[arr[pos].y][arr[pos].x] = 'x';
        check[i] = 0;
    }
}
 
int main(void)
{
    for (int i = 0; i < 5; i++)
    {
        cin >> map[i];
        for (int j = 0; j < 9; j++)
        {
            if ('A' <= map[i][j] && map[i][j] <= 'L') check[map[i][j] - 'A'= 1;
            if (map[i][j] == 'x') { arr[cnt].x = j; arr[cnt].y = i; cnt++; }
        }
    }
 
    dfs(00);
    
    for (int i = 0; i < 5; i++)
        cout << map[i] << endl;
 
    return 0;
}
cs

'Algorithms > DFS' 카테고리의 다른 글

[백준] 17300 - 패턴  (0) 2019.07.21
[백준] 3109 - 빵집  (0) 2018.09.17
[SWEA] 4223 - 삼성이의 트라우마  (0) 2018.09.08
[백준] 14889 - 스타트와 링크  (0) 2018.09.07
[백준] 9997 - 폰트  (0) 2018.08.31