Home > Back-end >  Small operation, consult. Save the children
Small operation, consult. Save the children

Time:12-31

As shown in figure, using c language to do these two topic

CodePudding user response:

[face] monkey2:019 PNG [/face]

CodePudding user response:

Question 9 of the answer is as follows: (10 can be done on the basis of question 9 code)
 
0100000100000000000000000000000000000000000000000
1010000010000000000000000000000000000000000000000
0101000001000000000000000000000000000000000000000
0010100000100000000000000000000000000000000000000
0001010000010000000000000000000000000000000000000
0000101000001000000000000000000000000000000000000
0000010000000100000000000000000000000000000000000
1000000010000010000000000000000000000000000000000
0100000101000001000000000000000000000000000000000
0010000010100000100000000000000000000000000000000
0001000001010000010000000000000000000000000000000
0000100000101000001000000000000000000000000000000
0000010000010100000100000000000000000000000000000
0000001000001000000010000000000000000000000000000
0000000100000001000001000000000000000000000000000
0000000010000010100000100000000000000000000000000
0000000001000001010000010000000000000000000000000
0000000000100000101000001000000000000000000000000
0000000000010000010100000100000000000000000000000
0000000000001000001010000010000000000000000000000
0000000000000100000100000001000000000000000000000
0000000000000010000000100000100000000000000000000
0000000000000001000001010000010000000000000000000
0000000000000000100000101000001000000000000000000
0000000000000000010000010100000100000000000000000
0000000000000000001000001010000010000000000000000
0000000000000000000100000101000001000000000000000
0000000000000000000010000010000000100000000000000
0000000000000000000001000000010000010000000000000
0000000000000000000000100000101000001000000000000
0000000000000000000000010000010100000100000000000
0000000000000000000000001000001010000010000000000
0000000000000000000000000100000101000001000000000
0000000000000000000000000010000010100000100000000
0000000000000000000000000001000001000000010000000
0000000000000000000000000000100000001000001000000
0000000000000000000000000000010000010100000100000
0000000000000000000000000000001000001010000010000
0000000000000000000000000000000100000101000001000
0000000000000000000000000000000010000010100000100
0000000000000000000000000000000001000001010000010
0000000000000000000000000000000000100000100000001
0000000000000000000000000000000000010000000100000
0000000000000000000000000000000000001000001010000
0000000000000000000000000000000000000100000101000
0000000000000000000000000000000000000010000010100
0000000000000000000000000000000000000001000001010
0000000000000000000000000000000000000000100000101
0000000000000000000000000000000000000000010000010


Thinking:
1. The subject is the application of figure, can through the two dimensional array to store data, which is simple, but storage efficiency than list) a [49] [49]
2. Analysis of the characteristics of the vertex, thus it is concluded that the presence of edge
Up: (I, j - 1)
Down: (I, j + 1)
Left: (I - 1, j)
Right: (I + 1, j) 0 & lt;=i<=6 0 & lt;=j
=63. Print a two-dimensional array can

The source code is as follows:
 
#include
using namespace std;

# define row 7
# define the column 7
# define Max 49
# define boundary_min 0
# define boundary_max 6
# define Null - 1

Int a [Max] [Max];

Void CreatGraphic ();
Int the up (int I, int j);
Int down (int I, int j);
Int left (int I, int j);
Int right (int, int j);

//void PrintMatrix

Int main ()
{
CreatGraphic ();

for(int i=0; i{
for(int j=0; J{
If (the up (I, j)!=Null)
{
A [(j) * column + I] [up] (I, j)=1;
A [up (I, j)] [(j) * column + I]=1;
}
If (down (I, j)!=Null)
{
A [(j) * column + I] [down] (I, j)=1;
A [down (I, j)] [(j) * column + I]=1;
}
If (left (I, j)!=Null)
{
A [(j) * column + I] [left] (I, j)=1;
A [left (I, j)] [(j) * column + I]=1;
}
If (right (I, j)!=Null)
{
A column + I] [(j) * (I, j) [right]=1;
A (I, j) [right] [(j) * column + I]=1;
}
}
}

for(int k=0; K{
for(int h=0; HCoutCout}

//cout<& lt;" 1 "& lt; return 0;
}

Void CreatGraphic ()
{
for(int i=0; ifor(int j=0; JA [I] [j]=0;
}

Int the up (int I, int j)
{
If (boundary_min & lt;=(j - 1) & amp; & (j - 1) & lt;=boundary_max)
Return ((j - 1) * column + I);
The else return Null;
}

Int down (int, int j)
{
If (boundary_min & lt;=(j + 1) & amp; & (j + 1) & lt;=boundary_max)
Return ((j + 1) * column + I);
The else return Null;
}

Int left (int, int j)
{
If (boundary_min & lt;=(I - 1) & amp; & (I - 1) & lt; nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related