[POJ3889]Fractal Streets
分析
简单递归模拟即可
注意转向
代码
#include<cstdio>
#include<cmath>
#define int long long
using namespace std;
int t,n,a,b;
int city(int k,int p,int& x,int& y){//2^2k,标号为 p 时的房屋的坐标 x,y
if(k==0)return x=1,y=1;
int t=(1<<(k-1));
if(p<=t*t)return city(k-1,p,y,x);
else if(p<=t*t*2)return city(k-1,p-t*t,x,y),y+=t;
else if(p<=t*t*3)return city(k-1,p-2*t*t,x,y),x+=t,y+=t;
else return city(k-1,p-3*t*t,y,x),y=t-y+1,x=2*t-x+1;
return 0;
}
signed main(){scanf("%lld",&t);
while(t--){scanf("%lld%lld%lld",&n,&a,&b);
int x1,y1,x2,y2;
city(n,a,x1,y1);
city(n,b,x2,y2);
double dis=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
dis=sqrt(dis*100);
printf("%lld\n",dis-(int)dis<0.5?(int)dis:(int)dis+1);
}
return 0;
}