本周Hihocoder的hiho一下
记得是2017年蓝桥杯B组的填空题
分治解决,观察每次变换,分成4块,将每块相对坐标都转换成左上角的相对坐标,边界是n为0时结果是1
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-9;
LL solve(int n, int x, int y)
{
if(n == 0) return 1;
LL m = 1 << (n-1);
if(x <= m && y <= m)
return solve(n-1, y, x);
if(x <= m && y > m)
return 1LL*m*m + solve(n-1, x, y-m);
if(x > m && y > m)
return 2LL*m*m + solve(n-1, x-m, y-m);
if(x > m && y <= m)
return 3LL*m*m + solve(n-1, m+1-y, 2*m+1-x);
}
LL n,x,y;
int main()
{
while(~scanf("%lld%lld%lld", &n,&x,&y))
printf("%lld
", solve(n,x,y));
return 0;
}