Pascal Knight Travel, a program for pascal Knight Travel

Updated on tourism 2024-04-11
13 answers
  1. Anonymous users2024-02-07

    If you want, leave an email and I'll send it to you.

  2. Anonymous users2024-02-06

    Dynamic programming. Dynamic equations: f[,j-2] or f[i-2,j-1] (Note that it's a Boolean!) )

  3. Anonymous users2024-02-05

    Although the input is different.

    But you can change it, the ** of the title.

    constmaxm=50;

    maxn=50;

    varm,n,x1,y1,x2,y2:integer;

    i,j,k,x,y:integer;

    map:array[-2..maxm+2,-2..maxn+2] of extended;

    beginfillchar(map,sizeof(map),0);

    readln(m,n,x1,y1,x2,y2);

    map[x1,y1]:=1;

    for i:=x1+1 to x2 do

    for j:=1 to m do

    map[i,j]:=map[i-1,j-2]+map[i-1,j+2]+map[i-2,j-1]+map[i-2,j+1];

    writeln(map[x2,y2]:0:0);

    end.

  4. Anonymous users2024-02-04

    Knight's Journey (Pascal).

    There is a chessboard with n*m (2<=n<=50, 2<=m<=50), and there is a Chinese chess horse at any point on the board, and the rules for the horse to move are: 1Horse Walking Japanese Character 2Horses can only go to the right.

    Task: When n and m are given, give the position of the horse's starting point and the position of the end point at the same time, and try to find the number of all paths from the beginning to the end point. For example: (n=10, m=10), (1,5) (start), (3,5) (end).

    Output: 2 (i.e. 2 paths from (1,5) to (3,5)).

    Input format: n, m, x1, y1, x2, y2 (represent n, m, start coordinates, end coordinates, respectively).

    Output format: Number of paths (0 if no path from start to end does not exist).

    From the (x1,y1) position, define the direction of the stages in order from left to right. The set of vault positions to the left of (x2,y2) up to (x2,y2) are all subproblems of (x2,y2), and the number of paths from the starting point to (x2,y2) is actually equal to the sum of the number of paths from the starting point to these sets of positions. You can calculate the number of paths at each point in each stage in the order of the phases.

    Phase I: The current column position of the Chinese chess horse (x1 i x2).

    State J: The position of the Chinese chess horse in the row of column i (1 i m).

    The state transition equation map[i,j]: the number of paths from the starting point (x1,y1) to (i,j).

    The specific algorithm is as follows:

    fillchar(map,sizeof(map),0);

    map[x1,y1]←1;

    for i←x1+1 to x2 do

    for j←1 to m do

    map[i,j]←map[i-1,j-2]+map[i-1,j+2]+map[i-2,j-1]+map[i-2,j+1];

    writeln(map[x2,y2]);

    Reference program】program qishiyouli;

    constmaxm=50;

    maxn=50;

    varm,n,x1,y1,x2,y2:integer;

    i,j,k,x,y:integer;

    map:array[-2..maxm+2,-2..maxn+2] of extended;

    beginfillchar(map,sizeof(map),0);

    readln(m,n,x1,y1,x2,y2);

    map[x1,y1]:=1;

    for i:=x1+1 to x2 do

    for j:=1 to m do

    map[i,j]:=map[i-1,j-2]+map[i-1,j+2]+map[i-2,j-1]+map[i-2,j+1];

    writeln(map[x2,y2]:0:0);

    end.

  5. Anonymous users2024-02-03

    Rub the experience.

    Rub the experience. Rub the experience.

    Rub the experience. Rub the experience.

  6. Anonymous users2024-02-02

    If you ask for all the solutions, you have to test 4 36= kinds, and the computer is too busy.

  7. Anonymous users2024-02-01

    The description of the title is not detailed enough.

    The problem is in terms of output.

    If the coordinates of the upper left corner of the board are (1,1) and the coordinates of the lower right corner are (n,m), then dfs(0,0,0); to change to dfs(1,1,0);

    writeln('(xy[j,1],'xy[j,2],'Changed to writeln('(xy[j,1],'m-xy[j,2]+1,')

    writeln('(n,' m,') to writeln('(n,' 1,')

  8. Anonymous users2024-01-31

    Question: Chessboard, n*m, Requirements:

    The rules for horses to walk are:1Horse Walking Japanese Character 2Horses can only go to the right.

    When n and m are entered, find a path from the bottom left corner to the top right corner.

    Re: Actually, your program is fine, after many debuggings, it has always been correct. In our fixed thinking, the first square on the board is (0,0), but if there is a special rule for the problem, then follow the rules. It's the same with you.

    The above is my reply, please decide.

  9. Anonymous users2024-01-30

    This is a classic type of backtracking, and there are many solutions on the Internet, you can check it out.

  10. Anonymous users2024-01-29

    It's all possible, but there is one thing you don't change when you modify the program.

    program aaa;

    constn=8; nsq=n*n;

    typeindex=1..n;

    vari,j:index;

    q:boolean;

    a:array[1..2,1..8]of integer;

    b:array[1..n,1..n]of integer;

    procedure try(x,y:index;i:integer;var q:boolean);

    vark,u,v:integer;

    q1:boolean;

    begink:=0;

    repeat

    k:=k+1;

    q1:=false;

    u:=x+a[1,k];

    v:=y+a[2,k];

    if (u>=1) and (u<=n) and(v>=1) and(v<=n) then

    if b[u,v]=0 then

    beginb[u,v]:=i;

    if ibegin

    try(u,v,i+1,q1);

    if not q1 then b[u,v]:=0;

    endelse q1:=true;

    end;until q1 or(k=8);

    q:=q1;

    end;begin

    a[1,1]:=-1;a[1,2]:=-2;a[1,3]:

    2;a[1,4]:=-1;a[1,5]:=1;a[1,6]:

    2;a[1,7]:=2;a[1,8]:=1;

    a[2,1]:=2;a[2,2]:=1;a[2,3]:

    1;a[2,4]:=-2;a[2,5]:=-2;a[2,6]:

    1;a[2,7]:=1;a[2,8]:=2;

    for i:=1 to n do

    for j:=1 to n do

    b[i,j]:=0;

    b[1,1]:=1;

    try(1,1,2,q);

    if q then

    for i:=1 to n do

    beginfor j:=1 to n do

    write(b[i,j]:5);

    writeln;

    endelse writeln('no solution!');

    end.

  11. Anonymous users2024-01-28

    if (x[j,1]+a[i,1]< n) and (x[j,2]+a[i,2]< m) and (x[j,1]+a[i,1]>=0) and (x[j,2]+a[i,2]>=0) then

    It should be if (x[j,1]+a[i,1]<=n) and (x[j,2]+a[i,2]<=m) and (x[j,1]+a[i,1]>=0) and (x[j,2]+a[i,2]>=0) then

    If it is not equal then it will not be reached.

  12. Anonymous users2024-01-27

    Knight travels have always been judged by RP.

    I might as well make it up again, I can do it, the first time it's right, the second time it's wrong, and the third time it's right...

  13. Anonymous users2024-01-26

    1. Conditional judgment 2. Array burst stack.

Related questions
9 answers2024-04-11

Of course there is, both grammatically and functionally, but in reality ......The application of C is much more powerful than Pascal, if you want to learn it it is recommended that you want to learn Pascal, and then learn C

6 answers2024-04-11

Meaning: 1. Tour; Roam.

Quote: Manan Chuen "Yanshan Night Talk: Starting from Huishen's Nationality": "It was only when he traveled to the Americas that people on that continent had the opportunity to come into contact with Buddhism. ” >>>More

4 answers2024-04-11

The Pascal compilation system is a system software. Pascal is the first structured programming language with rigorous syntax, clear hierarchy, easy to write and readable programs. Pascal language is widely used in various software, and the program is divided into name (self-proposed after program), setting (defined after var), start (begin), program (body), read (read read ln), and end (end), with strong structural hierarchy, rigorous and tight. >>>More

3 answers2024-04-11

1.Strings are used to store entire batches of character data. Strings are commonly used in programming to store characterized numeric data. >>>More

25 answers2024-04-11

halt: Exit the program.

exit: exit the process and function. If you are in the main program, the effect is the same as HALT. >>>More