Fractal City

Fractal City
Time limit: 10000 MS    Space limitations: 165536 KB
Problem Description

Urban planning is a big problem in urban construction. Unfortunately, many cities at the beginning of the construction is not a good plan, after the expansion of the city planning and inadequate problem began to appear. The city called Fractal idea of such a plan, as shown below:
After the expansion of urban scale, Fractal solution is the same as the original urban structure of the region in accordance with the figure a way around the building in the city, enhance the level of the city. For any level of the city, we start from the top left square blocks in accordance with the road grade. Although this program sucks, staff Fractal planning department still want to know, if the city developed to the level of N, numbered linear distance of two blocks A and B is. Refers to a block from the distance between the center blocks, each block side length is 10 meters square.

Input Format

Input file comprising a plurality of sets of test data, a first line T represents the integer number of test data.
Each test line comprising three integers N, A, B, and a level two cities represents the number of blocks.

Output Format

For each test, the answer in a separate output line, rounded to the nearest integer.

Sample input

Sample Input 1
. 3
. 1. 1 2
2 16. 1
. 3. 4 33 is

a sample input 2
2
. 3 46 is 56 is
. 3 21 is 42 is

Sample Output

Sample Output 1
10
30
50

Sample Output 2
32
61 is

 

 

This problem is like a long time I wanted to find too complicated QwQ ...

Change the order had no effect

Consider the contribution of other coordinate transformation as general discussions on the availability of answers to see code:

#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
int T; 
ll a,b,n; 
ll y1,x1; 
ll x2,y2; 
double dist(ll xx,ll xxx,ll yy,ll yyy) 
{ 
        return sqrt((1.000)*(xx-xxx)*(xx-xxx)+(1.000)*(yy-yyy)*(yy-yyy)); 
} 
void dfs(ll id,ll &x,ll &y,ll num) 
{     
    x=0;y=0;
    if(id==0) 
    return ;    
    ll m=(1<<id-1);
    ll d=m*m;
    ll pos=num/d;
    num=num%d;
    if(pos==0) {dfs(id-1,x,y,num);int tt=x;x=y;y=tt;}
    if(pos==1) {dfs(id-1,x,y,num);x=x;y=y+m;}
    if(pos==2) {dfs(id-1,x,y,num);x=x+m;y=y+m;}
    if(pos==3) {dfs(id-1,x,y,num);int ttt=x;x=2*m-1-y;y=m-1-ttt;}
    return ;
    
} 
int main() 
{ 
    cin>>T; 
    while(T--) 
    { 
        scanf("%lld%lld%lld",&n,&a,&b);
        x1=y1=x2=y2=0; 
        dfs(n,x1,y1,a-1); 
        dfs(n,x2,y2,b-1); 
        x1*=10;
        y1*=10;
        x2*=10;
        y2*=10;
        ll d=((1.000)*(dist(x1,x2,y1,y2))+0.5000);
        printf("%lld\n",d); 
    } 
}

 

 

 

Guess you like

Origin www.cnblogs.com/OIEREDSION/p/11370614.html