60分求助,第三第四个数据点过不了
查看原帖
60分求助,第三第四个数据点过不了
1563712
zzz20070313楼主2025/1/6 18:59
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int x1, x2, y2;

int exam(int i, int j)
{
    if (abs(i - x2) == 1 && abs(j - y2) == 2)
    {
        return 0;
    }
    else if (abs(i - x2) == 2 && abs(j - y2) == 1)
    {
        return 0;
    }
    else if (i == x2 && j == y2)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

int main()
{
    int y1;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    long long **sort = (long long **)malloc((x1 + 1) * sizeof(long long *));
    for (int i = 0; i <= x1; i++)
    {
        sort[i] = (long long *)malloc((y1 + 1) * sizeof(long long));
    }

    for (int i = 0; i <= x1; i++)
    {
        sort[i][0] = (exam(i, 0)) ? 1 : 0;
    }
    for (int i = 0; i <= y1; i++)
    {
        sort[0][i] = (exam(0, i)) ? 1 : 0;
    }

    for (int i = 1; i <= x1; i++)
    {
        for (int j = 1; j <= y1; j++)
        {
            if (exam(i, j))
            {
                sort[i][j] = sort[i][j - 1] + sort[i - 1][j];
            }
            else
            {
                sort[i][j] = 0;
            }
        }
    }

    printf("%lld\n", sort[x1][y1]);

    for (int i = 0; i <= x1; i++)
    {
        free(sort[i]);
    }
    free(sort);

    return 0;
}
2025/1/6 18:59
加载中...