풀이
분할정복을 이용하는 문제이다.
#include <iostream>
using namespace std;
int n, row, column;
int answer = 0;
void ZFunc(int y, int x, int size) {
if (y == row && x == column) {
cout << answer;
return;
}
if (row < y + size && row >= y && column < x + size && column >= x) {
ZFunc(y, x, size / 2);
ZFunc(y, x + size / 2, size / 2);
ZFunc(y + size / 2, x, size / 2);
ZFunc(y + size / 2, x + size / 2, size / 2);
}
else
answer += size * size;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int size = 1;
cin >> n >> row >> column;
size <<= n;
ZFunc(0, 0, size);
return 0;
}
'백준 > 기타' 카테고리의 다른 글
[백준/C++] 1780번: 종이의 개수 (0) | 2023.05.22 |
---|---|
[백준/C++] 2630번: 색종이 만들기 (0) | 2023.05.22 |
[백준/C++] 1992번: 쿼드트리 (0) | 2023.05.22 |
[백준/C++] 2667번 : 단지번호붙이기 (1) | 2023.05.18 |
[백준/C++] 18111번: 마인크래프트 (0) | 2023.04.19 |