[Reserved] $ CF171H $ explanations

Read the original

This title is \ (POJ3889 \) \ (Fractal \) \ (Streets \) is a weaker version, the original title practice to see my blog (password please private letter \ (Peter \) request) .

First of all, this is a \ (codeforces \) \ (2012 \) on April Fool's Day game \ (H \) title. Characteristics of the game April Fool's Day is the subject of strange, generally do not have formal title face, need to be derived by looking at the problem.

FIG observed problem, a problem is easy to see that in FIG fractal, through continuous copying, rotating the pattern becomes large. Each time copy, the original placed on the top left, top right copy, bottom left clockwise rotation \ (90 ^ \ circ \) after a copy, bottom right counterclockwise rotation \ (90 ^ \ circ \) after the copy.

Because of \ (n-\) the size of the city level \ (2N 2 ^ {} \) , \ (. 1-n-\) the size of the city level \ (2 ^ {2N-2} \) , will be difficult to think \ (n \) class city back \ (n-1 \) class city to find the location, the size of the problem by recursively shrinking.

The general idea is to find \ (n \) level cities \ (m \) coordinates of the point.

Provided from all points \ (0 \) numbering starts, \ (Calc (n-, m) \) returns \ (n-\) level cities \ (m \) coordinates of the point.

Each calculation \ (calc (n, m) \) , the first to give \ (Calc (. 1-n-, m \) $ MOD $ \ (2 ^ {2N-2}) \) , i.e. \ (m \) point \ (n-1 \) coordinates of the stage in the city.

The then \ (m / 2 ^ {2n -2} \) results judged \ (m \) the point at which \ (n-1 \) level cities.

I think this place for a long time, the middle is also cut off electricity times, is now rewritten version, if wrong, please tell immediately \ (Peter \) , grateful.

Why do this? Because each \ (2 ^ {2n} \ ) sizes are from the upper left city \ (2 ^ {2N-2} \) , the right upper \ (2 ^ {2N-2} \) , lower left \ (2 ^ { } 2-2N \) , the lower right \ (2 ^ {2n-2 } \) four small cities thereof. Sequence number is the first series End lower left \ (\ frac {1} { 4} \) , then compile the upper left \ (\ frac {1} { 4} \) , then compiled upper right \ (\ frac {1} { 4} \) , and finally the lower right ed \ (\ FRAC. 1 {{}}. 4 \) .

Thus, knowledge of the geometric transformation in the plane rectangular coordinate system can be obtained (can be clear below this private letter Q \ (Peter \) , to explain the line,Package will package, not to learn),

\ (m / 2 ^ {2n -2} = 0 \) , it indicates \ (m \) point in the lower left \ (n-1 \) level cities, according to \ (m \) point \ (n-1 \) coordinates of the stage in the city \ ((x, y) \ ) clockwise \ (90 ^ \ circ \) and then vertically flipped available \ (m \) at the point \ (n-\) coordinates of the stage in the city \ ((the y-, the X-) \) .

\ (m / 2 ^ {2n -2} = 1 \) , it indicates \ (m \) points at the upper left \ (n-1 \) level cities, according to \ (m \) point \ (n-1 \) coordinates of the stage in the city \ ((x, y) \ ) upward translation available \ (m \) point \ (n-\) coordinates of the stage in the city \ ((x, y + 2 ^ {n-1 }) \) .

\ (m / 2 ^ {2n -2} = 2 \) , it indicates \ (m \) point in the upper right \ (n-1 \) level cities, according to \ (m \) point \ (n-1 \) coordinates of the stage in the city \ ((x, y) \ ) rightward upwardly available \ (m \) point \ (n-\) coordinates of the stage in the city \ ((x + 2 ^ { n-1 }, {Y ^ n-2-+. 1}) \) .

\ (m / 2 ^ {2n -2} = 3 \) , it indicates \ (m \) point in the lower right \ (n-1 \) level cities, according to \ (m \) point \ (N- 1 \) coordinates of the stage in the city \ ((x, y) \ ) clockwise \ (90 ^ \ circ \) and then vertically flipped and then vertically flipped horizontally flipped last available \ (m \) point \ (n-\ ) coordinates of the stage in the city \ ((^ 2 ^ {n-NY-1,2--the -X-}. 1. 1) \) .

\ (Trick \) : For the calculation of the coordinates and the transfer may be used, such as \ (pair <int, int> \) type of function return value requires \ (the make \ _ pair (X, Y) \) .

Details: Recursive boundary is \ (0 \) level city, coordinates \ ((0,0) \) .

Then, enter the city series \ (A \) , serial number \ (b \) calculates the coordinates of the output is done slightly! If in doubt, see the comments section!

code show as below:

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int ret=0,f=1;
    char ch=getchar();
    while(ch>'9'||ch<'0')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        ret=(ret<<1)+(ret<<3)+ch-'0';
        ch=getchar();
    }
    return ret*f;
}
int a,b,ansx,ansy;
pair <int,int> calc(int n,int m)
{
    if(n==0)
        return make_pair(0,0);
    int len=1<<(n-1),mod=1<<(2*n-2),cas,x,y;
    pair<int,int> tmp=calc(n-1,m%mod);
    x=tmp.first;
    y=tmp.second;
    cas=m/mod;
    if(cas==1)
        return make_pair(x,y+len);
    if(cas==2)
        return make_pair(x+len,y+len);
    if(cas==0)
        return make_pair(y,x);
    if(cas==3)
        return make_pair(len*2-y-1,len-x-1);
}
int main()
{
    a=read();
    b=read();
    pair<int,int> ans;
    ans=calc(a,b);
    ansx=ans.first;
    ansy=ans.second;
    printf("%d %d\n",ansx,ansy);
    return 0;
}

Guess you like

Origin www.cnblogs.com/Peter0701/p/11273075.html