[Blue] Printing bridge cross FIG cup (C ++ Detailed)

【topic】

Time limit: 1.0s memory limit: 256.0MB
Xiaoming mechanism for a design of a cross-shaped logo (not ICRC ah), as follows:

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..

The other side also needs to be output in the computer dos window in the form of the character of the mark, and can control any number of layers.

Entry

3

Export

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$.. 

 Ideas analysis

Thinking: observe, then by level overlay method.

Hierarchy covering method: one layer is superimposed, from the outermost layer (bottom layer) starts; to achieve cross effect, by two rows column  opposite  matrix overlay covering  is made, when a finished outer cross did the next cross, need Note indent.

After completing roughly like this. Blue represents '' the red part represents the '$'

detailed steps

  • First of all a bottom surface of the cover '' (see below)

  • Next add a layer, it is to add a matrix of red, blue cover bottom above.

Continue to add a layer to form a cross.

And so on to complete the filling. Blue represents '' the red part represents the '$', two rotation to fill.

At the same time, there's a trick!

Use symmetry .

A matrix can be viewed as a matrix B transposed. Thus, the coordinate along the main diagonal symmetry.

Code

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    char map[150][150];
    cin >> n;
    
    int r = 4 * n + 5;	//矩阵长宽
    int t = n + 1;		//层的次数
    
    //填好第一层
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= r; j++){
            map[i][j] = '.';
        }
    }
    //剩下一层一层填
    for(int k = 1; k <= t; k++){
        //遍历每一层
        //以两层为一对,外层填 $ ,里层填 .
        for(int i = 1 + 2 * k; i <= r - 2 * k; i++){
            for(int j = 1 + 2 * k - 2; j <= r - (2 * k - 2); j++){
                //对称性
                map[i][j] = '$';
                map[j][i] = '$';
            }
        }
        for(int i = 1 + 2 * k + 1; i <= r - 2 * k - 1; i++){
            for(int j = 1 + 2 * k - 1; j <= r - (2 * k - 2) - 1; j++){
                //对称性
                map[i][j] = '.';
                map[j][i] = '.';
            }
        }
    }
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= r; j++){
           cout << map[i][j];
        }
        cout<<endl;
    }
    return 0;
}

to sum up

Really learn, and this method is the first time I saw, but also a lot of accumulation.

Published 62 original articles · won praise 34 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_41960890/article/details/105154140