-
<접근방법>
문제를 작은 문제로 쪼갤 수 있음을 알 수 있다.
<코드>
#include <iostream> #include <algorithm> #include <math.h> using namespace std; int n; int r, c; int res; void find(int len, int sy, int sx, int startNum) { if (sy == r && sx == c) { res = startNum; return; } int half = len / 2; int y = sy + half; int x = sx + half; if (r < y && c < x) { find(half, sy, sx, startNum); } else if (r < y && c >= x) { find(half, sy, x, startNum + half*half); } else if (r >= y && c < x) { find(half, y, sx, startNum + half * half * 2); } else { find(half, y, x, startNum + half * half * 3); } } int main() { cin >> n >> r >> c; find(pow(2, n), 0, 0, 0); cout << res << '\n'; }
이분의 코드가 재밌다.
'PS' 카테고리의 다른 글
백준 1992번 쿼드트리 (0) 2021.04.04 백준 11729번 하노이 탑 이동순서 (0) 2021.04.02 백준 1175번 배달 (0) 2021.03.29 백준 9328번 열쇠 (0) 2021.03.29 백준 16952번 체스판 여행 (0) 2021.03.29