SDJ( 수돈재 아님 ㅎ )

[C++] Mini Sudoku X 본문

알고리즘/Backjoon

[C++] Mini Sudoku X

ShinDongJun 2020. 1. 20. 18:02

문제 링크 : https://www.acmicpc.net/problem/9727

 

9727번: Mini Sudoku X

In Mini Sudoku X, there are 6 x 6 boxes to be filled with digits so that each row, column, main diagonal, and 2 x 3 square contains all the digits from 1 to 6. An example of a solution is as follows with the main diagonals shaded: Write a program that read

www.acmicpc.net

 

스도쿠가 올바른가 보기만 하면 되기 때문에

ㅡ 가로줄

| 세로줄

ㅁ 2x3칸 

X 대각선줄

 

이렇게 브루트포싱을 하면서 옳은지 확인하면 된다.

 

 

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<bits/stdc++.h>
#define endl '\n'
 
using namespace std;
 
int board[6][6];
 
int C(int &a, int k)
{
    if(a & ( 1 << k))
        return 1;
    else
        a += ( 1 << k);
 
    return 0;
}
 
int P()
{
    int a;
    for(int i = 0; i < 6++i)
    {
        a = 0;
        for(int j = 0; j < 6++j)
            if(C(a, board[i][j]))
                return 0;
    }
 
    for(int i = 0; i < 6++i)
    {
        a = 0;
        for(int j = 0; j < 6++j)
            if(C(a, board[j][i]))
                return 0;
    }
 
    for(int i = 0; i < 6++i)
    {
        if(i%2 == 0)
            a = 0;
 
        for(int j = 0; j < 3++j)
            if(C(a, board[i][j]))
                return 0;
    }
 
    for(int i = 0; i < 6++i)
    {
        if(i%2 == 0)
            a = 0;
        
        for(int j = 3; j < 6++j)
            if(C(a, board[i][j]))
                return 0;
    }
 
    a = 0;
    for(int i = 0; i < 6++i)
        if(C(a, board[i][i]))
            return 0;
 
    a = 0;
    for(int i = 0; i < 6++i)
        if(C(a, board[i][5-i]))
            return 0;
 
    return 1;
}
 
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t;
    cin >> t;
 
    for(int i = 1; i <= t; ++i)
    {
        for(int j = 0; j < 6++j)
        {
            for(int z = 0; z < 6++z)
            {
                cin >> board[j][z];
            }
        }
 
        cout << "Case#" << i << ": " << P() << endl;
    }
 
    return 0;
}

'알고리즘 > Backjoon' 카테고리의 다른 글

[C++] 7576 - 토마토  (0) 2020.01.20
[C++] 1260 - DFS와 BFS  (0) 2020.01.20
[C++] 15918 - 랭퍼든 수열쟁이야!!  (0) 2020.01.20
[C++] 14925 - 목장 건설하기  (0) 2020.01.17
[C++] 2981 - 검문  (0) 2020.01.16
Comments