As shown in figure, there is a 8 * 8 squares, requirements from the start, to different colors of another random lattice,
Requirements: 1. Must go through all of the 64's;
2. Each square only after a time,
CodePudding user response:
Whether can only arrive at adjacent frames?
CodePudding user response:
Think of it like a mosquito coil, spiral circle, there is no place to use temporary data first
CodePudding user response:
reference 1st floor lhylhy response: once only reached the adjacent grid? Only move up and down or so and not inclined to move CodePudding user response:
Tags: X direction: X11... X99 Y direction: Y11... Y99 Two-dimensional array y [1.. 9] [9] 1.. Mobile: X or Y direction plus or minus 1 If cannot arrive by X or Y direction and subtract a next, not marked points and tag number less than 64 already, it is failure CodePudding user response:
This is orsay problem, more than 20 years ago, had counselling, CodePudding user response:
# include & lt; Stdio. H> # define N 100 # define n 6 Int main () { Int dx [8], dy [8]. Dx [0]=2, dy [0]=1; Dx [1]=1, dy [1]=2; Dx [2]=1, dy [2]=2; Dx [3]=2, dy [3]=1; Dx [4]=2, dy [4]=1; Dx [5]=1, dy [5]=2; Dx [6]=1, dy [6]=2; Dx [7]=2, dy [7]=1; Printf (" * * * * * * * * * * * * * * * * * * * * \ n "); For (int e=0; E For (int r=0; R { Int flag [N] [N]={0}; Int x [N], [N] y, log [N]={0}; Int beginx=e, beginy=r; Flag [beginx] [beginy]=1; Int stepx=beginx, stepy=beginy; [0]=beginx x, y [0]=beginy; Int t=1; Int sum=1; While (t> 0) { While (1) { If (log [t]==8) { The log [t]=0; Goto L1. } Stepx=stepx + dx [log [t]]; Stepy=stepy + dy [log [t]]. If (stepx>=n | | stepy>=n | | stepx<0 | | stepy<0) { Stepx -=dx [log [t]]. Stepy -=dy [log [t]]. The log [t] + +; Goto L0; } If (flag [stepx] [stepy]==1) { Stepx -=dx [log [t]]. Stepy -=dy [log [t]]. The log [t] + +; } If (flag [stepx] [stepy]==0) { Flag [stepx] [stepy]=1; Sum++; [t] x=stepx; [t] y=stepy; break; } L0:; } If (sum==n * n) goto the write; T++; Goto L2; L1: //flag [x [t]] [[t]] y=0; T -; Flag [x [t]] [[t]] y=0; The sum -; Stepx=stepx - dx [log [t]]. Stepy=stepy - dy [log [t]]. The log [t] + +; L2:; } goto out; Write: Printf (" \ nbeginx=% d, beginy=% d \ n ", e, r); Out:; } return 0; } CodePudding user response:
reference jossyu reply: 3/f Quote: refer to 1st floor lhylhy response: Whether can only arrive at adjacent frames? Only move up and down or so, can't inclined to mobile The exhaustive, step by step, CodePudding user response:
Exhaustion is slow, there should be a kind of special strategy can quickly find a feasible solution CodePudding user response:
Using depth first search, CodePudding user response:
Can try to traverse the same color, then consider different color of the grid, CodePudding user response:
Definition, left, right, four directions under the weight of,3,2,1 [4] if null is 0, cannot choose, according to the weights of traverse a is ok, can have a try, CodePudding user response:
references to the tenth floor lhylhy response: can have a try first to traverse the same color, then consider different color grid, Is said to consider for the same color of two squares A and B, with A starting point for B as A destination for all traversal? Ha ha this is impossible, Because the entire board of red and green grid number are equal, and each step can only from red to green, or from green to red, so, if one path beginning red end with red, red plaid throughout the path will be one more than the green grid, this means that either the board did not go to the one in the green grid, or have a red plaid walk for more than one times, in the same way, also is not possible from green green at the end of the traversal path in the beginning, CodePudding user response:
The refer to 12 floor yyfhz reply: Quote: reference to the tenth floor lhylhy response: Can try to traverse the same color, then consider different color grid, Is said to consider for the same color of two squares A and B, with A starting point for B as A destination for all traversal? Ha ha this is impossible, Because the entire board of red and green grid number are equal, and each step can only from red to green, or from green to red, so, if one path beginning red end with red, red plaid throughout the path will be one more than the green grid, this means that either the board did not go to the one in the green grid, or have a red plaid walk for more than one times, in the same way, also is not possible from green green at the end of the traversal path in the beginning, As long as the last of the different color tile set at the end of the same color next to,