FIG cross previous printing papers (analog)

Successive questions questions Print Cross map

资源限制
时间限制:1.0s   内存限制:256.0MB

$Daily English:

I want to remind people the only thing on the planet is this: We
rely on Mother Earth to survive.
The only thing I want is to awaken all humans on the planet that we are living on Mother Earth.

Problem Description

Xiaoming a cross-shaped design of the logo (not ah ICRC) for a mechanism, 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.

Input Format

A positive integer n (n <30) represents the number of layers required for printing graphics.
Output format
corresponding to the number of layers surrounding the marker.

Sample input 1

1

Sample output 1

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

Sample input 2

3

Sample output 2

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

Tip
Please carefully observe the sample, with particular attention to the number and location of the output of the period.

Ideas:

This problem a bit mean (I read a long time, a start has been led to think too complicated I do not know how to waste a lot of time !!! !! hands fortunately did not give up !!!). A I finally was up! ! ! Haha ~ (quietly happy for a while)

Brute analog (or in fact a bit of brain ~):
intermediate cross first are initialized, then grab two starting points, of each ring is divided into four parts,
each part, and the drawing direction of the number of steps necessary to record each section.
See specific code ~

Code:

#include <iostream>
#include <vector>
using namespace std;
char mp[150][150];
//dir: up,down,left,right:0,1,2,3
int step_x[] = {-1,1,0,0};
int step_y[] = {0,0,-1,1};
struct Point
{
    int x;
    int y;
    Point(int xx,int yy)
    {
        x = xx;
        y = yy;
    }
};
vector<Point>vec;

//设置每一部分的方向+步数
void initVec(int *dc_d,int *dc_c)
{
    if(vec.size())vec.clear();
    for(int i = 0; i < 4; i++)
    {
        vec.push_back(Point(dc_d[i],dc_c[i]));
    }
}
//绘制每一个部分
void work(int sx,int sy)
{
    for(int i = 0; i < 4; i++)
    {
        int dir = vec[i].x;
        int cnt = vec[i].y;
        int xx = sx + step_x[dir];
        int yy = sy + step_y[dir];
        mp[xx][yy] = '$';
        for(int j = 1; j < cnt; j++)
        {
            xx += step_x[dir];
            yy += step_y[dir];
            mp[xx][yy] = '$';
        }
        sx = xx;
        sy = yy;
    }
}
int main()
{
    int n;
    cin>>n;
    //图像大小
    int m = 5 + 4 * n;
    //图像初始化
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < m; j++)
        {
            mp[i][j] = '.';
        }
    }
    Point center(2*n+2,2*n+2);
    //中间十字
    mp[center.x][center.y] = '$';
    for(int i = 0; i < 4; i++)
    {
        int x1 = center.x + step_x[i];
        int y1 = center.y + step_y[i];
        mp[x1][y1] = '$';
        x1 += step_x[i];
        y1 += step_y[i];
        mp[x1][y1] = '$';
    }
    int y0 = center.y - 2,z0 = center.y + 2;
    //方向
    int dc_d0[] = {0,3,0,3};
    int dc_d1[] = {0,2,0,2};
    int dc_d2[] = {1,3,1,3};
    int dc_d3[] = {1,2,1,2};
    int x = 2 * n + 2;
    int y = y0,z = z0;
    //每圈分成4个部分
    for(int i = 1; i <= n; i++)
    {
        //步数
        int dc_c[] = {2*i,2,2,2*i};
        //两个起点的列
        y -= 2;
        z +=  2;
        mp[x][y] = '$';
        mp[x][z] = '$';
        //左上
        initVec(dc_d0,dc_c);
        work(x,y);
        //右上
        initVec(dc_d1,dc_c);
        work(x,z);
        //左下
        initVec(dc_d2,dc_c);
        work(x,y);
        //右下
        initVec(dc_d3,dc_c);
        work(x,z);
    }
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cout<<mp[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Published 301 original articles · won praise 38 · views 30000 +

Guess you like

Origin blog.csdn.net/tb_youth/article/details/104826918