递归下去,不过要处理好坐标变换,不然很恶心
1 /* *********************************************** 2 Author :BPM136 3 Created Time :2018/7/15 12:25:52 4 File Name :3889.cpp 5 ************************************************ */ 6 7 #include8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 using namespace std;15 16 typedef long long ll;17 18 const int con[] = { 0,1,3,2};19 const int can_add_x[] = { 0,0,1,1};20 const int can_add_y[] = { 0,1,0,1};21 const int tur_P[] = { 1,0,-1,0};22 23 ll bit4[35];24 ll bit2[35];25 26 ll sqr(ll x) { return x*x; }27 28 struct point {29 ll x,y;30 point() {}31 point(ll _x,ll _y) : x(_x),y(_y) {}32 void init() {33 x=y=0;34 }35 point operator+(const point &b) const {36 point ret;37 ret.x=x+b.x;38 ret.y=y+b.y;39 return ret;40 }41 point operator-(const point &b) const {42 point ret;43 ret.x=x-b.x;44 ret.y=y-b.y;45 return ret;46 }47 double mean() {48 double ret=0;49 ret=sqr(x)+sqr(y);50 return sqrt(1.0*ret);51 }52 };53 54 point get_id(int n,ll x) {55 point ret; ret.init();56 if(n==1) {57 if(x==1) ret=point(1,1);58 if(x==2) ret=point(1,2);59 if(x==3) ret=point(2,2);60 if(x==4) ret=point(2,1);61 return ret;62 }63 if(x<=bit4[n-1]) {64 point tmp=get_id(n-1,x);65 ret=point(tmp.y, tmp.x);66 } else67 if(x<=bit4[n-1]*2) {68 point tmp=get_id(n-1,x-bit4[n-1]);69 ret=point(tmp.x, tmp.y+bit2[n-1]);70 } else71 if(x<=bit4[n-1]*3) {72 point tmp=get_id(n-1,x-bit4[n-1]*2);73 ret=point(tmp.x+bit2[n-1], tmp.y+bit2[n-1]);74 } else {75 point tmp=get_id(n-1, x-bit4[n-1]*3);76 ret=point(bit2[n]+1-tmp.y, bit2[n-1]+1-tmp.x);77 }78 return ret;79 }80 81 int main() {82 bit4[0]=1; for(int i=1;i<31;i++) bit4[i]=bit4[i-1]*4;83 bit2[0]=1; for(int i=1;i<31;i++) bit2[i]=bit2[i-1]*2;84 85 int T;86 scanf("%d",&T);87 while(T--) {88 int n,h,o;89 scanf("%d%d%d",&n,&h,&o);90 point id_h=get_id(n,h);91 point id_o=get_id(n,o);92 cout<<(ll) ( ((id_h-id_o).mean())*10 )<