알고리즘
백준 2072번 오목 C++
영춘권의달인
2022. 12. 21. 17:19
https://www.acmicpc.net/problem/2072
2072번: 오목
19x19크기의 바둑판에, 돌을 놓을 좌표가 주어지면 이 게임이 몇 수만에 끝나는 지를 알아보려고 한다. 사용하고자 하는 바둑판의 모양은 위의 그림과 같으며, (1, 1)이 가장 왼쪽 위의 좌표이고 (19
www.acmicpc.net
단순한 구현 문제
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
enum class StoneType {
NOTHING,
BLACK,
WHITE
};
enum Dir {
UP,
UR,
RIGHT,
DR,
DOWN,
DL,
LEFT,
UL
};
int n;
int ans = -1;
int dRow[8] = { -1,-1,0,1,1,1,0,-1 };
int dCol[8] = { 0,1,1,1,0,-1,-1,-1 };
vector<vector<StoneType>> board;
int GetSameStoneCnt(int row, int col, StoneType stoneType, Dir dir) {
int ret = 0;
while (true) {
row += dRow[(int)dir];
col += dCol[(int)dir];
if (row <= 0 || row >= 20) break;
if (col <= 0 || col >= 20) break;
if (board[row][col] != stoneType) break;
ret++;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
board = vector<vector<StoneType>>(20, vector<StoneType>(20, StoneType::NOTHING));
cin >> n;
StoneType currType = StoneType::NOTHING;
for (int i = 1; i <= n; i++) {
if (i % 2 == 0) currType = StoneType::WHITE;
else currType = StoneType::BLACK;
int r, c;
cin >> r >> c;
board[r][c] = currType;
int val1 = GetSameStoneCnt(r, c, currType, UP) + GetSameStoneCnt(r, c, currType, DOWN);
int val2 = GetSameStoneCnt(r, c, currType, UR) + GetSameStoneCnt(r, c, currType, DL);
int val3 = GetSameStoneCnt(r, c, currType, RIGHT) + GetSameStoneCnt(r, c, currType, LEFT);
int val4 = GetSameStoneCnt(r, c, currType, DR) + GetSameStoneCnt(r, c, currType, UL);
if (val1 == 4 || val2 == 4 || val3 == 4 || val4 == 4) {
ans = i;
break;
}
}
cout << ans;
}