分形

分形之城

原题链接

关于哪个对称,坐标两个一一对应就可以,x对应x,y对应y。
对称轴写错了QAQ,上下两个都是关于x轴做对称变换,关于y轴变号

#include<iostream>
#include<cmath>

using namespace std;

typedef long long LL;
typedef pair<LL,LL> PLL;

PLL calc(LL n,LL m)
{
    if(n==0)return {0,0};
    LL len=1LL<<(n-1),cnt=1LL<<(2*n-2);//n-1级边长为len,总个数为4的n-1次也就是2的2n-2次
    PLL pos=calc(n-1,m%cnt);//n-1级中的坐标位置
    LL x=pos.first,y=pos.second;
    LL z=m/cnt;//第几块
    if(z==0)//第0块
        return make_pair(y,x);
    if(z==1)
        return make_pair(x,y+len);
    if(z==2)
        return make_pair(x+len,y+len);
    if(z==3)
        return make_pair(2*len-y-1,len-x-1);
}

int main()
{
    int m;
    cin>>m;
    while(m--)
    {
        LL N,A,B;
        cin>>N>>A>>B;
        auto ac=calc(N,A-1);
        auto bc=calc(N,B-1);
        double x=ac.first-bc.first,y=ac.second-bc.second;
        printf("%.0f\n",sqrt(x*x+y*y)*10);
    }
    return 0;
}
posted @ 2021-02-19 15:18  Tsukinousag1  阅读(55)  评论(0)    收藏  举报