Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- XR Interaction Toolkit
- 시뮬레이션
- 누적 합
- 그래프
- 자료구조
- 투 포인터
- 수학
- 다익스트라
- VR
- 정렬
- 알고리즘
- BFS
- 브루트포스
- 다이나믹 프로그래밍
- 그리디 알고리즘
- 유니티
- 백트래킹
- 트리
- Team Fortress 2
- Unreal Engine 5
- ue5
- 우선순위 큐
- DFS
- 백준
- c++
- 문자열
- 구현
- 스택
- 유니온 파인드
- 재귀
Archives
- Today
- Total
1일1알
백준 15671번 오델로 C++ 본문
https://www.acmicpc.net/problem/15671
15671번: 오델로
오델로(Othello)는 검은색, 또는 하얀색 작은 원판을 6x6의 판 위에 늘어놓는 보드 게임이다. 보통 일본에서는 オセロ(오세로), 국내에서는 오델로라 부르고 있다. 어원은 오셀로 희곡으로 오셀로의
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;
int dRow[8] = { -1,-1, 0, 1, 1, 1, 0,-1 };
int dCol[8] = { 0, 1, 1, 1, 0,-1,-1,-1 };
enum class Turn {
BLACK,
WHITE
};
int n;
vector<vector<char>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
board = vector<vector<char>>(7, vector<char>(7, '.'));
board[3][3] = 'W';
board[4][4] = 'W';
board[3][4] = 'B';
board[4][3] = 'B';
cin >> n;
Turn currTurn = Turn::BLACK;
while (n--) {
int r, c;
cin >> r >> c;
char myStone;
if (currTurn == Turn::BLACK) myStone = 'B';
else myStone = 'W';
board[r][c] = myStone;
for (int i = 0; i < 8; i++) {
int nextRow = r;
int nextCol = c;
vector<pair<int, int>> tmp;
while (true) {
nextRow += dRow[i];
nextCol += dCol[i];
if (nextRow < 1 || nextRow > 6 || nextCol < 1 || nextCol > 6 || board[nextRow][nextCol] == '.') {
tmp.clear();
break;
}
if (board[nextRow][nextCol] == myStone) {
break;
}
tmp.push_back({ nextRow,nextCol });
}
for (auto a : tmp) {
board[a.first][a.second] = myStone;
}
}
if (currTurn == Turn::BLACK) currTurn = Turn::WHITE;
else currTurn = Turn::BLACK;
}
int blackCnt = 0;
int whiteCnt = 0;
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= 6; j++) {
if (board[i][j] == 'B') blackCnt++;
if (board[i][j] == 'W') whiteCnt++;
cout << board[i][j];
}
cout << "\n";
}
if (blackCnt > whiteCnt) cout << "Black";
else cout << "White";
}
'알고리즘' 카테고리의 다른 글
백준 11536번 줄 세우기 C++ (0) | 2023.05.13 |
---|---|
백준 12933번 오리 C++ (0) | 2023.05.12 |
백준 25206번 너의 평점은 C++ (0) | 2023.05.09 |
백준 2331번 반복수열 C++ (0) | 2023.05.08 |
백준 17828번 문자열 화폐 C++ (0) | 2023.05.07 |