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
- 알고리즘
- 다이나믹 프로그래밍
- c++
- 시뮬레이션
- 유니티
- 백트래킹
- BFS
- 정렬
- ue5
- 브루트포스
- VR
- 투 포인터
- XR Interaction Toolkit
- 트리
- 그래프
- Team Fortress 2
- 문자열
- 수학
- 유니온 파인드
- 다익스트라
- 스택
- Unreal Engine 5
- 재귀
- 누적 합
- 구현
- 우선순위 큐
- 자료구조
- DFS
- 백준
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준 2615번 오목 C++ 본문
https://www.acmicpc.net/problem/2615
2615번: 오목
오목은 바둑판에 검은 바둑알과 흰 바둑알을 교대로 놓아서 겨루는 게임이다. 바둑판에는 19개의 가로줄과 19개의 세로줄이 그려져 있는데 가로줄은 위에서부터 아래로 1번, 2번, ... ,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;
int dRow[4] = { -1,0,1,1 };
int dCol[4] = { 1,1,1,0 };
vector<vector<int>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
board = vector<vector<int>>(19, vector<int>(19));
for (int i = 0; i < 19; i++)
for (int j = 0; j < 19; j++)
cin >> board[i][j];
bool finish = false;
for (int i = 0; i < 19; i++) {
for (int j = 0; j < 19; j++) {
if (board[i][j] == 0) continue;
for (int k = 0; k < 4; k++) {
int nextRow = i;
int nextCol = j;
int prevCnt = 0;
int nextCnt = 1;
while (true) {
nextRow -= dRow[k];
nextCol -= dCol[k];
if (nextRow < 0 || nextRow >= 19) break;
if (nextCol < 0 || nextCol >= 19) break;
if (board[nextRow][nextCol] != board[i][j]) break;
prevCnt++;
}
nextRow = i;
nextCol = j;
while (true) {
nextRow += dRow[k];
nextCol += dCol[k];
if (nextRow < 0 || nextRow >= 19) break;
if (nextCol < 0 || nextCol >= 19) break;
if (board[nextRow][nextCol] != board[i][j]) break;
nextCnt++;
}
int cnt = prevCnt + nextCnt;
if (cnt == 5 && prevCnt == 0) {
finish = true;
cout << board[i][j] << "\n";
cout << i + 1 << " " << j + 1;
}
}
}
}
if (finish == false) cout << 0;
}
'알고리즘' 카테고리의 다른 글
백준 2331번 반복수열 C++ (0) | 2023.05.08 |
---|---|
백준 17828번 문자열 화폐 C++ (0) | 2023.05.07 |
백준 17829번 222-풀링 C++ (0) | 2023.05.05 |
백준 2508번 사탕 박사 고창영 C++ (0) | 2023.05.04 |
백준 3060번 욕심쟁이 돼지 C++ (0) | 2023.05.03 |