AcWing 98. 分形之城 (分形)

题目地址: https://www.acwing.com/problem/content/100/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ll long long
#define PLL pair<ll,ll>
pair<long long,long long>calc(long long n,long long m)
{
    if(n==0) return make_pair(0,0);
    long long len=(long long)1<<(n-1),cnt=(long long)1<<(2*n-2);///注意不强制转换成long long会wrong
    pair<long long,long long>pos=calc(n-1,m%cnt);
    long long x=pos.first,y=pos.second;
    long long z=m/cnt;
    if(z==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);
   else return make_pair(2*len-y-1,len-x-1);
    //return;
}
/*
PLL calc(ll n,ll m)
{
    if (n==0)
        return make_pair(0,0);
    ll len=1LL<<(n-1),cnt=1LL<<(2*n-2);
    PLL pos=calc(n-1,m%cnt);
    ll x=pos.first,y=pos.second;
    ll z=m/cnt;
    if (z==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);
    return make_pair(2*len-1-y,len-1-x);
}*/

int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
      long long n;
       long long a,b;
       scanf("%lld%lld%lld",&n,&a,&b);
       pair<long long,long long>x1=calc(n,a-1);
       pair<long long,long long>x2=calc(n,b-1);
      long long x=x1.first-x2.first;
      long long y=x1.second-x2.second;
       double ans=(sqrt((double)(x*x+y*y))*10);
       printf("%.0lf\n",ans);

   }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值