VioletaBabel
1780번: 종이의 개수 본문
#include<cstdio>
int paper[2187][2187], count[3];
void countPaper(int n, int x, int y);
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]);
countPaper(n, 0, 0);
printf("%d\n%d\n%d", count[0], count[1], count[2]);
}
void countPaper(int n, int x, int y)
{
bool same = 1;
for (int i = y; i < y + n && same == 1; ++i)
for (int j = x; j < x + n && same == 1; ++j)
if (paper[y][x] != paper[i][j])
same = 0;
if (same == 1)
++count[paper[y][x] + 1];
else
{
n /= 3;
countPaper(n, x, y);
countPaper(n, x + n, y);
countPaper(n, x + (2 * n), y);
countPaper(n, x, y + n);
countPaper(n, x + n, y + n);
countPaper(n, x + (2 * n), y + n);
countPaper(n, x, y + (2 * n));
countPaper(n, x + n, y + (2 * n));
countPaper(n, x + (2 * n), y + (2 * n));
}
}
'백준 > 백준-C++' 카테고리의 다른 글
| 1463번: 1로 만들기 (0) | 2017.06.03 |
|---|---|
| 11052번: 붕어빵 판매하기 (0) | 2017.06.01 |
| 2003번: 수들의 합 [재채점 틀림] (0) | 2017.05.29 |
| 12791번: Starman (0) | 2017.05.29 |
| 12790번: Mini Fantasy War (0) | 2017.05.29 |