#include<bits/stdc++.h>
using namespace std;
int N,T;
long long S,D;
double dis0;
long long dis;
struct co{ //x行y列,从0开始
long long x;
long long y;
};
long long qpow(int a,int b){
long long ans=1;
while(b){
if(b&1) ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
co cal(long long id,int level){ //id是编号,level是等级
if(level==1){
co res;
if(id==0){
res.x=0; res.y=0;
}else if(id==1){
res.x=0; res.y=1;
}else if(id==2){
res.x=1; res.y=1;
}else if(id==3){
res.x=1; res.y=0;
}
return res;
}
long long num=qpow(2,2*(level-1));
long long la=qpow(2,level-1);
int d=id/num;
long long lx=cal(id%num,level-1).x;
long long ly=cal(id%num,level-1).y;
co ans;
if(d==0){
ans.x=ly; ans.y=lx;
}else if(d==1){
ans.x=lx; ans.y=ly+la;
}else if(d==2){
ans.x=lx+la; ans.y=ly+la;
}else if(d==3){
ans.x=2*la-ly-1; ans.y=la-lx-1;
}
return ans;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%lld%lld",&N,&S,&D);
S--; D--;
co cs,cd;
cs=cal(S,N);
cd=cal(D,N);
dis0=sqrt((cs.x-cd.x)*(cs.x-cd.x)+(cs.y-cd.y)*(cs.y-cd.y))*10;
dis=(long long)(dis0+0.5);
printf("%lld\n",dis);
}
return 0;
}
in:
1
22 11451419198100 1919810114514
无输出,return 3221225620
然后调试的时候发现第一次执行 cal 时,num 居然为 0,简直让我以手抚膺坐长叹