AcWing 98. 分形之城
原题链接
困难
作者:
geats兔
,
2024-04-05 03:03:07
,
所有人可见
,
阅读 1
C++ 代码
#include<iostream>
#include<cstdio>
#include<math.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
ll a,b;
int n;
PII get(int n,ll a){
if(n==0) return {0,0};
ll block=1ll<<(2*n-2),len=1ll<<(n-1);
PII res=get(n-1,a%block);
int z=a/block;
if(z==0) res={res.y,res.x};
else if(z==1) res={res.x,res.y+len};
else if(z==2) res={res.x+len,res.y+len};
else res={2*len-1-res.y,len-1-res.x};
return res;
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d%lld%lld",&n,&a,&b);
auto p=get(n,a-1);
auto q=get(n,b-1);
ll dx=p.x-q.x,dy=p.y-q.y;
double dist=sqrt(dx*dx+dy*dy)* 10;
printf("%.0lf\n",dist);
}
return 0;
}