VS能过但是OJ过不了
查看原帖
VS能过但是OJ过不了
850740
BuXiangMing楼主2023/4/6 11:44
#include<cstdio>
using namespace std;
int ux[8] = { -2,-1,1,2,2,1,-1,-2 };
int uy[8] = { 1,2,2,1,-1,-2,-2,-1 };
long long int chess[25][25]; int chess_x, chess_y, horse_x, horse_y;
bool judge(int now_x, int now_y, int hx, int hy) {
    for (int k = 0; k < 8; k++)
        if (now_x == hx + ux[k] && now_y == hy + uy[k])
            return false;
    return true;
}
int main() {
    scanf("%d%d%d%d", &chess_x, &chess_y, &horse_x, &horse_y);
    for (int i = 0; i <= chess_y; i++)
        for (int j = 0; j <= chess_x; j++) {
            if (i == horse_y && j == horse_x) {
                chess[j][i] = 0;
                continue;
            }
            if (i == 0 && j == 0) {
                chess[0][0] = 1;
                continue;
            }
            chess[i][j] = chess[i - 1][j] + chess[i][j - 1];
            if (judge(j, i, horse_x, horse_y))
                continue;
            else
                chess[i][j] = 0;
        }
    printf("%lld", chess[chess_y][chess_x]);
}
2023/4/6 11:44
加载中...