当前位置:网站首页>A horse stopped a pawn

A horse stopped a pawn

2022-06-21 14:47:00 User 6978604

Title source :C Language network 1266

Problem description

On the chessboard A There is a river crossing pawn , Need to get to the goal B spot . The rules of pawn walking : You can go down 、 Or to the right . At the same time on the chessboard C There's a horse on the other side , The point where the horse is located and all the points that can be reached in one step of jumping are called the control points of the opposing horse . So it's called “ A pawn crossing the river ”. The chessboard is represented by coordinates ,A spot (0, 0)、B spot (n, m)(n, m For no more than 15 The integer of ), The same coordinates of the horse's position need to be given . Now I ask you to calculate the number of soldiers from A Point can reach B The number of paths of points , Suppose the horse's position is fixed , It's not a step by step .

Input

Four data in a row , respectively B Point coordinates and horse coordinates .( Make sure all the data is clear )

Output

A data , Indicates the number of paths .

The sample input

6 6 3 5

Sample output

6

problem solving

/*
 * @Author: YaleXin
 * @Date: 2020-05-24 13:34:01
 * @LastEditTime: 2020-05-24 14:16:01
 * @LastEditors: YaleXin
 * @Description:
 * @FilePath: \my_c_workspace\dotcpp\1266.c
 * @ Prayer does not appear BUG
 */
#include <stdio.h>
/**
 * @x :  Abscissa of the horse   @y :  Ordinate of horse 
 */
int path[16][16] = {0}, sum = 0, n, m, x, y;
/**
 *  Initialize the exclusion zone 
 */
void setHorse() {
    path[x][y] = 1;
    if ((x - 2) >= 0 && (y - 1) >= 0) path[x - 2][y - 1] = 1;
    if ((x - 1) >= 0 && (y - 2) >= 0) path[x - 1][y - 2] = 1;
    if ((x - 2) >= 0 && (y + 1) <= m) path[x - 2][y + 1] = 1;
    if ((x - 1) >= 0 && (y + 2) <= m) path[x - 1][y + 2] = 1;
    if ((x + 2) <= n && (y - 1) >= 0) path[x + 2][y - 1] = 1;
    if ((x + 1) <= n && (y - 2) >= 0) path[x + 1][y - 2] = 1;
    if ((x + 2) <= n && (y + 1) <= m) path[x + 2][y + 1] = 1;
    if ((x + 1) <= n && (y + 2) <= m) path[x + 1][y + 2] = 1;
}
void findPath(int nowX, int nowY) {
    if (nowX == n && nowY == m) {
        sum++;
        return;
    }
    //  First to the right 
    if ((nowY + 1) <= m && !path[nowX][nowY + 1]) findPath(nowX, nowY + 1);
    //  following 
    if ((nowX + 1) <= n && !path[nowX + 1][nowY]) findPath(nowX + 1, nowY);
}
int main() {
    scanf("%d%d%d%d", &n, &m, &x, &y);
    setHorse();
    //  First to the right 
    if (!path[0][1]) findPath(0, 1);
    //  following 
    if (!path[1][0]) findPath(1, 0);
    printf("%d", sum);
    return 0;
}
原网站

版权声明
本文为[User 6978604]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211444492848.html