莫欺少年穷,修魔之旅在这开始—>算法提高课题解
思路:以中心为原点,每次都分成四块,然后递归处理子问题
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
PLL get(LL n,LL a) //得到等级为 n 的 a 的坐标
{
if(!n) return {0,0};
LL block=1ll<<n*2-2,len=1<<n-1;
PLL p=get(n-1,a%block);
LL x=p.first,y=p.second,z=a/block;
if(z==0) return {-y-len,-x+len}; //左上角
else if(z==1) return {x+len,y+len}; //右上角
else if(z==2) return {x+len,y-len}; //右下角
else return {y-len,x-len}; //左下角
}
int main()
{
int T;
cin>>T;
while(T--)
{
LL n,a,b;
cin>>n>>a>>b;
PLL pa=get(n,a-1),pb=get(n,b-1);
double dx=pa.first-pb.first,dy=pa.second-pb.second;
printf("%.lf\n",sqrt(dx*dx+dy*dy)*5);
}
return 0;
}