본문 바로가기
SWEA

[SWEA] 11315. 오목 판정

by 콩순이냉장고 2021. 8. 12.

문제 URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AXaSUPYqPYMDFASQ&categoryId=AXaSUPYqPYMDFASQ&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

문제 접근법 : 

이중for문으로 확인하는거 8방향으로 연속된게 5개이상인지 확인해도 괜찮지만

딱 4방향으로 확인해도 됩니다. 우상단, 우측, 우하단, 아래쪽 4방향으로 연속된것만 확인해도 충분히 풀수있는 오목이상 상이 되는것을 찾을 수 있습니다.

 

소스코드 :

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
//By 콩순이냉장고
#include <bits/stdc++.h>
using namespace std;
char board[20][20];
int n;
int dy[4= { -1,0,1,1 };
int dx[4= { 1,1,1,0 };
void input() {
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> board[i][j];
}
bool isrange(int y, int x) {
    return 0 <= y && y < n && 0 <= x && x < n;
}
int path(int y, int x, int dir) {
    if (!isrange(y, x)) return 0;
    if (board[y][x] == '.'return 0;
    return 1 + path(y + dy[dir], x + dx[dir], dir);
}
void solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < 4; k++) {
                if (path(i, j, k) >= 5) {
                    cout << "YES" << "\n";
                    return;
                }
            }
        }
    }
    cout << "NO" << "\n";
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int test;
    cin >> test;
    for (int i = 1; i <= test; i++) {
        input();
        cout << "#" << i << " ";
        solve();
    }
    
}
 
cs

 

모르느점 혹은 궁금한점 어떤질문이든 댓글은 언제나 환영입니다.