-
You should be on the path.
Press the F1 key to switch to the selection state.
-
#include
#define maxsize 100
#define n 8
int board[8][8];Define the board.
int htry1[8]=;
Stores an incremental array of subscripts for each exit position of the horse relative to the current position line*
int htry2[8]=;
Stores an array of increments* in the column subscript for each exit position of the horse* relative to the current position
struct stackstack[maxsize];Define a stack array.
int top=0;Stack pointers.
void initlocation(int xi,int yi);The coordinates of the starting position of the horse on the board.
int trypath(int i,int j);The horses try in each direction until they have the entire board.
void display();Outputs the path the horse walks.
void initlocation(int xi,int yi)
int trypath(int i,int j)
a[h]=number;Deposit the number of entries into the array a[8]}}
for(h=0;h<8;h++) according to the number of feasible paths, sorted according to the following table, and put them into the array d[8].
a[s]=9;
if(top>=63) returns 1 if the entire board is played
return (1);
find=0;Indicates that the next location was not found.
for(h=0;h<8;h++) in eight directions.
if(find==1) if the next location is found to enter the stack.
else Otherwise, back stack.
return (0);
void display()
printf("begin with %d board:", 8*(x-1)+y);
initlocation(x-1,y-1);Call the start coordinate function}
-
A greedy algorithm that steps on a chessboard.
Problem Description] Traversal problem for horses. On an 8 8-squares board, start from any of the designated squares and find the shortest path for the horse to go through each square of the board and only once. 【Preliminary Design】 First of all, this is a search problem, which is solved by using depth-first search.
The algorithm is as follows: 1. Enter the initial position coordinates x,y; 2. Step C: If C> 64 outputs a solution, returns the subnodes of the previous step C-- x,y) c to calculate the eight directions of (x,y), and selects the feasible subnode Cycle through all feasible subnodes, step C++ repeats 2 Obviously, (2) is a recursive process, roughly as follows:
#define n 8 ……void dfs(int x,int y,int count) for(i=0;i <8;++i) }
-
It depends on what algorithm you use, if it is an ordinary depth-first search, the difference between 6*6 and 8*8 is very huge, the time complexity of the depth-first search itself is exponential, for a point to do 8 directions to try, then theoretically, in the worst-case 6*6 and 8*8 scale under the scale of time complexity o(8 36) and o(8 64) respectively,You calculate how many times the difference between 8 64 and 8 36,6*6 is useless no matter how fast。
-
This one was previously found on the Internet (I don't know the original connection) and can complete the basic requirements.
#include
#include
using namespace std;
const int maxsize=512;
const int n=8;
int board[8][8];Define the board.
int htry1[8]=;
Stores an incremental array of subscripts for each exit position of the horse relative to the current position line*
int htry2[8]=;
Stores an array of increments* in the column subscript for each exit position of the horse* relative to the current position
struct stack stack[maxsize];Define a stack array.
int top=-1;Stack pointers.
void initlocation(int xi,int yi);The coordinates of the starting position of the horse on the board.
int trypath(int i,int j);The horses try in each direction until they have the entire board.
void display();Outputs the path the horse walks.
void main()
cout <<"Horses from (" <-1)
a[h]=number;Deposit the number of entries into array a}}
for(h=0;h<8;h++)
a[s]=9;
director=stack[top].director;
if(top>=63) returns 1 if the entire board is played
return (1);
find=0;Indicates that the next location was not found.
for(h=director+1;h<8;h++)
if(find==1)else
return 0;
Outputs the path the horse walks.
void display()
cout <
I use yes.
Just include the lib folder in the open installation directory to the lib directory of the vc. >>>More
People are afraid of being famous, and pigs are afraid of being strong" >>>More
It's possible that your question was duplicated and deleted! >>>More
Because there is a need, because it can't be done.
Card,,The network is not good, it's stuck.,There's a problem with your system, I suggest you redo the system.,Try it from the new game!!