递推与递归3:分形之城
作者:
总打瞌睡的天天啊
,
2024-08-04 12:23:51
,
所有人可见
,
阅读 1
//考察分形的递推 ,看题分析
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long LL;
struct Point
{
LL x,y;
};
//获得n等级下a的坐标
Point get(LL n,LL a)
{
if(n==0)return {0,0};
LL block=1ll<<n*2-2,len=1ll<<n-1;
auto p=get(n-1,a%block);
LL x=p.x,y=p.y;
int z=a/block;
if(z==0)return {y,x};
else if(z==1)return{x,y+len};
else if(z==2)return{x+len,y+len};
return {len*2-1-y,len-1-x};
}
int main()
{
int n;
cin>>n;
while(n--)
{
LL t,a,b;
cin>>t>>a>>b;
auto pa=get(t,a-1);
auto pb=get(t,b-1);
//计算俩点间距离
double dx=pa.x-pb.x,dy=pa.y-pb.y;
printf("%.0lf\n",sqrt(dx*dx+dy*dy)*10);
}
return 0;
}