题解如下
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
long long a,b;
long long ai[31];
short ggbond[4][4]={{2,0,0,3},{3,1,1,2},{0,2,2,1},{1,3,3,0}},gg1,gg2;//记录每种情况的方向:0上,1下,2左,3右
int feix[4][4]={{0,1,1,0},{1,0,0,1},{0,0,1,1},{1,1,0,0}};
int feiy[4][4]={{0,0,1,1},{1,1,0,0},{0,1,1,0},{1,0,0,1}};//处理各点坐标
long long xa,xb,ya,yb;
int main()
{
ai[0]=1;
for(int i=1;i<=30;i++)ai[i]=ai[i-1]*2;
scanf("%d",&n);
for(int h=1;h<=n;h++)
{
scanf("%d%lld%lld",&k,&a,&b);
a-=1;b-=1;
xa=0,xb=0,ya=0,yb=0;
gg1=2,gg2=2;
for(int i=k-1;i>=0;i--)
{
int q=a/(ai[i]*ai[i]);
xa+=ai[i]*feix[gg1][q];
ya+=ai[i]*feiy[gg1][q];
gg1=ggbond[gg1][q];
a%=(ai[i]*ai[i]);
int qi=b/(ai[i]*ai[i]);
xb+=ai[i]*feix[gg2][qi];
yb+=ai[i]*feiy[gg2][qi];
gg2=ggbond[gg2][qi];
b%=(ai[i]*ai[i]);
}//记录各点的坐标
printf("%.0lf\n",sqrt(((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)))*10);//两点距离公式
}
return 0;
}