| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- D2
- D3
- 프로그래머스
- network
- c++
- OS
- algorithm
- 감상문
- 알고리즘
- Programmers
- 네트워크
- 데이터베이스
- 독서
- 법의학
- LeetCode
- swea
- algogritim
- 재테크/투자
- data structure
- 운영체제
- 백준
- language
- cs
- SW Expert Academy
- BOJ
- db
- Computer Science
- 자료구조
- 문제풀이
- Database
Archives
- Today
- Total
선택은 나의 것
[SWEA] 11315 오목 판정 본문
문제
SWEA 11315 : 오목 판정
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
접근
BFS를 통해 돌이 놓인 위치에서 갈 수 있는 모든 방향으로 전진하며 돌의 개수를 세 주었다. 이때 문제 제목에 오목이라고 쓰여있어서 연속되는 돌의 개수가 5개여야 하는 것으로 착각할 수 있지만, 문제의 조건을 보면 연속하는 돌의 개수가 다섯 개 이상이면 "YES"이다. 따라서 BFS를 돌 때 counter의 수가 5이상이면 break를 하고 "YES"를 출력해주면 된다.
코드
#include <iostream>
#include <queue>
#define endl "\n"
using namespace std;
struct qnum {
int x, y, go, counter;
};
int main() {
int test_case, dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}, dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
cin >> test_case;
for (int t = 1; t <= test_case; t++) {
int n, chk = 0;
char map[25][25];
cin >> n;
queue<qnum> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
if (map[i][j] == 'o') {
q.push({i, j, 0, 1});
q.push({i, j, 1, 1});
q.push({i, j, 2, 1});
q.push({i, j, 3, 1});
q.push({i, j, 4, 1});
q.push({i, j, 5, 1});
q.push({i, j, 6, 1});
q.push({i, j, 7, 1});
}
}
}
while (!q.empty()) {
qnum f = q.front();
q.pop();
if (f.counter >= 5) {
chk = 1;
break;
}
int newx = f.x + dx[f.go];
int newy = f.y + dy[f.go];
if (newx >= 0 && newx < n && newy >= 0 && newy < n && map[newx][newy] == 'o')
q.push({newx, newy, f.go, f.counter + 1});
}
cout << "#" << t << " ";
if (chk == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
'☽ Algorithm > SWEA' 카테고리의 다른 글
| [SWEA] 10912 외로운 문자 (0) | 2021.08.15 |
|---|---|
| [SWEA] 1285 아름이의 돌 던지기 (0) | 2021.08.14 |
| [SWEA] 1970 쉬운 거스름돈 (0) | 2021.08.13 |
| [SWEA] 1979 어디에 단어가 들어갈 수 있을까 (0) | 2021.08.12 |
| [SWEA] 11688 Calkin-Wilf tree 1 (0) | 2021.08.11 |
Comments