2019 soft labor practice third operation

1, Github Address: https://github.com/YangSlim/031702243

2, PSP form

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 1h 1h
Estimate Estimate how much time this task requires 20.5h 21.5h
Development Develop 5h 4h
Analysis Needs analysis (including learning new technologies) 2h 5h
Design Spec Generate design documents 1h 1h
Design Review Design Review 0.5h 0.5h
Coding Standard Code specifications (development of appropriate norms for the current development) 1h 0.5h
Design Specific design 1h 0.5h
Coding Specific coding 1h 1h
Code Review Code Review 1h 1h
Test Test (self-test, modify the code, submit modifications) 2h 1.5h
Reporting report 2h 2h
test repor testing report 0.5h 1h
Size Measurement Computing workload 0.5h 0.5h
Postmortem & Process Improvement Plan Later summarized, and process improvement plan 2h 2h
total 20.5h 21.5h

3, problem-solving process

Sudoku got this problem, according to questions asked when is 4,6,8,9 Sudoku grids is needed particularly to determine whether intrauterine digital duplicates. Then try to write a function to determine the line where the vacancy and that column has a digital repetition, the judgment of the Palace of additional write function, so that the rows and columns finished in judgment to determine what the house is like. Finally traversed by DFS, backtracking.

Palace of the judgment

bool judge_palace(int x, int row, int col, int key)/*4、6、8、9宫格需要对宫进行判断 */
{
    int i, j;

    /* b为x所在的小九宫格左顶点竖坐标 */
    int  b = x / m / row * row;

    /* c为x所在的小九宫格左顶点横坐标 */
    int  c = x % m / col * col;
    for (i = b; i < b + row; i++)
    {
        for (j = c; j < c + col; j++)
        {
            if (a[i][j] == key)
            {
                return false;
            }
        }
    }
    return true;
}

Rows and columns judge finished, direct call function to determine the Palace

bool judge_row_col(int x, int key)/*判断数独的每一列每一行是否重复*/
{
    int row = x / m;
    int col = x % m;
    for (int i = 0; i < m; i++)/*判断行 */
    {
        if (a[row][i] == key)
        {
            return false;
        }
    }
    for (int i = 0; i < m; i++)/*判断列*/
    {
        if (a[i][col] == key)
        {
            return false;
        }
    }
    if (m == 4)/*4宫格*/
    {
        if (judge_palace(x, 2, 2, key))/* 宫的大小2*2 */
        {
            return true;
        }
        return false;

    }
    else if (m == 6)/*6宫格*/
    {
        if (judge_palace(x, 2, 3, key))/* 宫的大小2*3 */
        {
            return true;
        }
        return false;
    }
    else if (m == 8)/*8宫格*/
    {
        if (judge_palace(x, 4, 2, key))/* 宫的大小4*2 */
        {
            return true;
        }
        return false;
    }
    else if (m == 9)/*9宫格*/
    {
        if (judge_palace(x, 3, 3, key))/* 宫的大小3*3 */
        {
            return true;
        }
        return false;
    }
    return true;
}

DFS traversal enter the number

void DFS(int x)/* 深搜构造数独 */
{
    if (sign)/*如果已经完成 直接返回*/
    {
        return;
    }
    if (x == m * m)/* 说明所有的都符合,数独求解完毕,退出递归 */
    {
        print();
        sign = 1;
        return;
    }
    int row = x / m;
    int col = x % m;
    if (a[row][col] != 0)/*当前位置不为空则判断下一空*/
    {
        DFS(x + 1);
    }
    else
    {
        for (int i = 1; i <= m; i++)
        {
            if (judge_row_col(x, i))
            {
                a[row][col] = i;
                DFS(x + 1);
                /* 如果构造不成功,还原当前位 */
                a[row][col] = 0;
            }
        }
    }
}

Test Results

3 grids

4 grids

5 grids

6 grids

7 grids

8 grids

9 Palace grid

Performance Analysis

to sum up

The job took a lot of time to read and output files above, because before no input parameters on the command line and then run the code, quite a few detours. There is familiar with how to upload files locally to Github.

Guess you like

Origin www.cnblogs.com/ycj202595/p/11580989.html