본문 바로가기
Algorithm

[BAEKJOON] 1074번: Z

by Y06 2021. 9. 27.

1074번 문제이다.

사진을 누르면 문제로 이동한다.

문제는 C++언어로 구현하였다.

 

 

#include <iostream>

using namespace std;

int n, r, c;
int ans;

void Z(int y, int x, int size)
{
    if (y == r && x == c)
    {
        cout << ans << '\n';
        return;
    }

    // r,c가 현재 사분면에 존재한다면
    if (r < y + size && r >= y && c < x + size && c >= x)
    {
        // 1사분면 탐색
        Z(y, x, size / 2);
        // 2사분면 탐색
        Z(y, x + size / 2, size / 2);
        // 3사분면 탐색
        Z(y + size / 2, x, size / 2);
        // 4사분면 탐색
        Z(y + size / 2, x + size / 2, size / 2);
    }
    else
    {
        ans += size * size;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> r >> c;
    Z(0, 0, (1 << n));
    return 0;
}

'Algorithm' 카테고리의 다른 글

[BAEKJOON] 10828번: 스택  (0) 2021.09.30
[BAEKJOON] 1874번: 스택 수열  (0) 2021.09.30
[BAEKJOON] 2018번: 수들의 합 5  (0) 2021.09.26
[BAEKJOON] 2750번: 수 정렬하기  (0) 2021.09.21
[BAEKJOON] 1806번: 부분합  (0) 2021.09.21