1780번: 종이의 개수
N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1의 세 값 중 하나가 저장되어 있다. 우리는 이 행렬을 적절한 크기로 자르려고 하는데, 이때 다음의 규칙에 따라 자르려고 한다.
www.acmicpc.net
#include <stdio.h>
using namespace std;
short paper[2190][2190];
int arr[5];
short cutting(int x, int y, int num) {
if (num == 1) {
return paper[y][x];
}
bool different = false;
int cur, saved, t_arr[5] = { 0, };
num /= 3;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cur = cutting(x + j * num, y + i * num, num);
t_arr[cur + 1]++;
if (different) continue;
if ((i != 0 || j != 0) && saved != cur) {
different = true;
}
saved = cur;
}
}
if (different || cur == 2) {
for (int i = 0; i < 3; i++) {
arr[i] += t_arr[i];
}
return 2;
}
else return cur;
}
int main() {
int n; scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &paper[i][j]);
}
}
cutting(0, 0, n);
if (!arr[0] && !arr[1] && !arr[2]) arr[paper[0][0] + 1]++;
printf("%d\n%d\n%d\n", arr[0], arr[1], arr[2]);
return 0;
}| 좋은 C언어 공부법 소개 (0) | 2021.01.10 |
|---|---|
| 백준 14888번 연산자 끼워넣기 C/C++ (0) | 2020.12.19 |
| 백준 14502번 연구소 C (0) | 2020.12.15 |
| 백준 1436번 영화감독 숌 C++ (0) | 2020.12.12 |
| 백준 7568번 덩치 C++ (0) | 2020.12.11 |
댓글 영역