Luo Gu P5461 pardon prisoners of war solution to a problem

P5461 pardon prisoners

Topic background

With anti-cheat system, some of the game in the month of plagiarism cheating players were caught out!

Title Description

Existing \ (2 ^ n \ times 2 ^ n (n \ le10) \) were cheating stand waiting a square matrix of kkksc03 pleasure. kkksc03 decided to pardon a number of cheaters. He will square matrix is divided into four smaller square matrix, each smaller side length is half of the original matrix of the matrix. All cheaters in which the upper left corner of a matrix that will be forgiven, and the remaining three small matrix, each matrix continues to be divided into four smaller matrices, then pardon those who cheat in the same way until the matrix can no longer ...... points go up. All cheaters have not been pardoned are punished will be punished by the name of Brown.

Gives nn, please fate output per cheaters, where 0 represents forgiven, 1 for not being forgiven.

Input Format

An integer \ (the n-\) .

Output Format

\ (2 ^ n \ times 2 ^ n \) of 01 matrices, each representing whether people were pardoned. There is a space between numbers.

Sample input and output

Input # 1

3

Output # 1

0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 1 0 1
0 0 0 0 1 1 1 1
0 0 0 1 0 0 0 1
0 0 1 1 0 0 1 1
0 1 0 1 0 1 0 1
1 1 1 1 1 1 1 1

[Thinking]

Recursion + partition
This is a very interesting topic
is considered personal modeling capabilities or the ability to understand their own
modeling capabilities it is clear that the ability to establish a model in mind
according to the subject to imagine a recursive process is simulated in the mind
then come recursive formula
so their ability to recognize what is it?
That is, I do not think they have their own modeling capabilities
and then take it for granted, thinking that looking at the
final results have not yet want to be on for a long time
so this time you have to move a bit of paper and a pen
to draw a clearer picture thinking
this is the understanding of their ability !!! !
I do not have the ability to model and no understanding of their ability to cause so This question took me a long time

This is a \ (2 ^ n \) square, so every time a square divided into four congruent when the
side length is just to meet a multiple of 2, and can be composed of square
because you \ (2 ^ n \) after each divided by two separate,
becomes \ (the n-2 ^ {- 1} \) , or a multiple of two
so you can continue to 1 minute know
this is before you write the code needed to thoroughly understand the

Then, because it is the top-left corner of the square can be forgiven
is 0.
So just recursive other three squares on it

I think that each recursive recursive their two pairs of vertices on the corner
and then to determine the change in the square by the changes in their vertex positions
so as to achieve recursive

Consider first the upper right corner of this small square

vertex positions in the upper left corner (1,5) above, X1 has not changed
can be obtained x1 = x1;
but indeed changed y1
became 5, y2 is the original position is just large square half the length + 1
can be obtained y1 = y1 + (y2 - y1 + 1) / 2 or y1 = y1 + (y2 - y1 ) / 2 + 1
both a reason
and bottom right vertices (4,8 ) above
x2 is half of the original can be obtained
x2 = (x2 - x1 + 1 ) / 2;
Why is this so? Instead x2 = x2 / 2 it
as an example of which is equal to 1 x1,
where x1 is not always equal to 1,
then if x1 is equal to the individual you bring x2 = x2 / 2 will find a big problem
so we consider I said that right!
y2 is not changed so available
y2 = y2
so easily launched
(x1, y1 + (y2 - y1 + 1) / 2, x2 / 2, y2)
to the
thus can process the upper right corner of the square the

Know these other two squares on the good can launch it
here, I will not say more
because the process is exactly the same as above
considered separately for each coordinate changes just fine

Direct given:
the lower left corner of the square: (x1 + (x2 - x1 + 1) / 2, y1, x2, y1 + (y2 - y1) / 2);
lower right corner of a square: (x1 + (x2 - x1 + 1) / 2, y1 + ( y2 - y1 + 1) / 2, x2, y2);

[Complete code]

#include<iostream>
#include<cstdio>

using namespace std;
const int Max = 1030;
int a[11] = {1,2,4,8,16,32,64,128,256,512,1024};
int f[Max][Max];

void acioi(int x1,int y1,int x2,int y2)
{
    if(x1 == x2 && y1 == y2)
    {
        f[x1][y1] = 1;
        return;
    }
    acioi(x1 + (x2 - x1 + 1) / 2,y1 + (y2 - y1 + 1) / 2,x2,y2);
    acioi(x1,y1 + (y2 - y1 + 1) / 2,x1 + (x2 - x1) / 2,y2);
    acioi(x1 + (x2 - x1 + 1) / 2,y1,x2,y1 + (y2 - y1) / 2);
}

int main()
{
    int n;
    cin >> n;
    acioi(1,1,a[n],a[n]);
    for(int i = 1;i <= a[n];++ i)
    {
        for(int j = 1;j <= a[n];++ j)
            cout << f[i][j] << " ";
        cout << endl; 
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/acioi/p/11616918.html