-
백준 1780번 종이의 개수PS 2021. 4. 8. 02:09
<코드>
#include <iostream> #include <algorithm> #include <math.h> using namespace std; #define MAX 2188 int n; int oneCnt, zeroCnt, moneCnt; int map[MAX][MAX]; void counting(int num) { if (num == -1) { moneCnt++; } else if (num == 0) { zeroCnt++; } else { oneCnt++; } } void solve(int y, int x, int size) { if (size == 1) { counting(map[y][x]); return; } bool br = false; for (int i = y; i < y + size; i++) { for (int j = x; j < x + size; j++) { if (map[y][x] != map[i][j]) { br = true; break; } if (br) break; } } if (br) { for (int i = y; i < y + size; i += (size/3)) { for (int j = x; j < x + size; j += (size/3)) { solve(i, j, size / 3); } } } else { counting(map[y][x]); } } int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> map[i][j]; } } solve(0, 0, n); cout << moneCnt << '\n'; cout << zeroCnt << '\n'; cout << oneCnt << '\n'; return 0; }
반응형'PS' 카테고리의 다른 글
백준 10830번 행렬 제곱 (0) 2021.04.08 백준 20164 홀수 홀릭 호석 (0) 2021.04.08 백준 13171 A (0) 2021.04.06 백준 17478 재귀함수가 뭔가요? (0) 2021.04.06 백준 1629 곱셈 (0) 2021.04.06