Home > Back-end >  Happy New Year to the brothers and sisters. By the way, ask a question.
Happy New Year to the brothers and sisters. By the way, ask a question.

Time:09-25



Suppose there is a big cube is similar to a rubik's cube by n * n * n small stack, use graph structure to store, each small pieces for a node, a value of 0 or 1, now wants to non-zero cube surface nodes to dig out, make the human eye can see small values are 1, pay attention to every block, dig out the human eye would see the new surface, non-zero node in the new surface continue to dig out, until the human eye can see small values are 1, the case may be, when to dig down along a certain direction are all zero, the cube to dig a hole,

Please everybody, glad to give some thought to also go,

Thank you,

CodePudding user response:

A, define the type of three dimensional array
Type
TArr=array [0.. 19, 0.. 19, 0), 19] of Byte;//data model 20 * 20 * 20
TArr1=array [0.. 19, 0.. 19] of Byte;//merge longitudinal model fully

Second, define global array variable
Var M: TArr;//data model
M1: TArr;//merge longitudinal appear a

Three, the initialization
Description: three dimensional array X (horizontal) Y (solid) Z (vertical), cyclic variable I, j, k,
Procedure TForm1. Button1Click (Sender: TObject);
Var I, j, k: integer;
The begin
Randomize.
For k:=0 to 19 do
For j:=0 to 19 do
For I:=0 to 19 do
M [I, j, k] :=the random (2);//a random number 0 and 1
end;

Four, search combined longitudinal fully
Var T: Boolean;
I, j, k, kk: integer;
The begin
Kk:=5;//merge 1-6 layer
For I:=0 to 19 do
For I:=0 to 19 do
The begin
T:=True;
For k:=0 to kk do
If [k, I, j]=1: then T=False;
If T then [I, j] : M1=0
Else M1: [I, j]=1;
end;
end;

Five, the graphics
Through the Memo character graphics, if draw pictures, write their own,

CodePudding user response:

reference 1st floor lyhoo163 response:
a, define the type of three dimensional array
Type
TArr=array [0.. 19, 0.. 19, 0), 19] of Byte;//data model 20 * 20 * 20
TArr1=array [0.. 19, 0.. 19] of Byte;//merge longitudinal model fully

Second, define global array variable
Var M: TArr;//data model
M1: TArr;//merge longitudinal appear a

Three, the initialization
Description: three dimensional array X (horizontal) Y (solid) Z (vertical), cyclic variable I, j, k,
Procedure TForm1. Button1Click (Sender: TObject);
Var I, j, k: integer;
The begin
Randomize.
For k:=0 to 19 do
For j:=0 to 19 do
For I:=0 to 19 do
M [I, j, k] :=the random (2);//a random number 0 and 1
end;

Four, search combined longitudinal fully
Var T: Boolean;
I, j, k, kk: integer;
The begin
Kk:=5;//merge 1-6 layer
For I:=0 to 19 do
For I:=0 to 19 do
The begin
T:=True;
For k:=0 to kk do
If [k, I, j]=1: then T=False;
If T then [I, j] : M1=0
Else M1: [I, j]=1;
end;
end;

Five, the graphics
Through the Memo characters, graphics, if drawing, write their own right,

Thank you taught to folly, you give the program is the meaning: M1 is a 2 d data, returns it seems to be the three-dimensional M projection to planar M1, if there is a M column 1, is projected to 1, if all is 0, the projection is 0,

I need should be steady for 1 M all surface return after, I again express my meaning:
Suppose there is a big cube is similar to a rubik's cube by n * n * n small stack, use graph structure to store, each small pieces for a node, a value of 0 or 1, is now the cubes fully immersed in water, water will dissolve cube surface of non-zero node, the surface preserved for 1, pay attention to each block dissolve, and is a new surface in contact with the water, continue to dissolve non-zero node, in the new surface until all come into contact with the water of small values are 1, there are two situations may occur, if one is dissolved down along a certain direction are all zero, opened a hole in the cube; 2 cube could be dissolved into multiple disconnect is not connected to the object, the rest of the program results back surface of 1 nodes,

CodePudding user response:

Look very NB, algorithms don't understand, static, etc

CodePudding user response:

The random array (0, 1),
Merge the layers on the value of the node, if all is zero, equal to zero (pass), as long as there is a 1, equal to 1 (can't), it expressed the node you dissolve,
The key is to find the data model,
Write a program, see below:

Tip: to simulate 20 * 20 * 20 matrix, random number fill (0, 1), 5 layers merge, merger & gt; 9, there is no 0 (opaque),

CodePudding user response:

The
reference 4 floor lyhoo163 reply:
(0, 1) to an array of random generation,
Merge the layers on the value of the node, if all is zero, equal to zero (pass), as long as there is a 1, equal to 1 (can't), it expressed the node you dissolve,
The key is to find the data model,


Elder brother, thank you for help, I felt as if I don't mean that, dissolve the node is not just in one direction, but the three axes namely before and after the up and down or so six direction (from one direction to dissolve in water, can continue to dissolve in the rest of the five directions), whenever dissolve within a node, the surrounding five nodes are exposed to water, is likely to be dissolved, somewhat similar to the floodfill, or traverse,

In addition, the program needs to return all of the rest of the surface nodes, seemingly should return at least ability of 3 d array said node coordinates,

Thank you very much,

CodePudding user response:

Finally clearly stated,
  • Related