알고리즘 문제/BOJ
12759번 틱! 택! 토!
parkit
2019. 1. 8. 18:39
728x90
반응형
https://www.acmicpc.net/problem/12759
브루트 포스 및 구현 문제다.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <iostream> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> using namespace std; int Map[4][4] = { 0, }; int start = 0; bool stop = false; int isFinished(int turn) { int ret = 0; // 행 for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (Map[i][j] != turn) break; if (j == 2) return turn; } } // 열 for (int j = 0; j < 3; j++) { for (int i = 0; i < 3; i++) { if (Map[i][j] != turn) break; if (i == 2) return turn; } } // 오른쪽 아래 대각선 for (int i = 0; i < 3; i++) { if (Map[i][i] != turn) break; if (i == 2) return turn; } // 왼쪽 아래 대각선 for (int i = 0; i < 3; i++) { if (Map[i][2 - i] != turn) break; if (i == 2) return turn; } return 0; } int main(void) { int r = 0, c = 0, win = 0, next = 0; scanf("%d", &start); for(int i=0; i<9; i++) { if (i % 2 == 0) next = start; else { if (start == 2) next = 1; else next = 2; } scanf("%d %d", &r, &c); --r; --c; Map[r][c] = next; if (!stop) { win = isFinished(next); if (win != 0) stop = true; } } printf("%d\n", win); return 0; } | cs |
728x90
반응형