求助,本地跑样例正确,0分无法找到问题
查看原帖
求助,本地跑样例正确,0分无法找到问题
1387740
ja1u0va楼主2024/12/20 20:59
#include <iostream>

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

int vis[12][12][12][12][4][4];
int map[12][12];
int cnt;

struct pos
{
    int x, y, dir;
} fa, co;

bool operator==(pos p1, pos p2)
{
    if (p1.x == p2.x && p1.y == p2.y)
        return true;
    else
        return false;
}

void operator++(pos &p)
{
    int x = p.x + dx[p.dir];
    int y = p.y + dy[p.dir];
    if (map[x][y] != 0)
    {
        p.x = x;
        p.y = y;
    }
    else
    {
        p.dir = (p.dir + 1) % 4;
    }
}

int main()
{
    for (int i = 1; i <= 10; ++i)
    {
        for (int j = 1; j <= 10; ++j)
        {
            char tmp;
            scanf("%c", &tmp);
            if (tmp != '*')
                map[i][j] = 1;
            if (tmp == 'F')
            {
                fa = {i, j, 0};
            }
            if (tmp == 'C')
            {
                co = {i, j, 0};
            }
        }
        getchar();
    }

    // for (int i = 0; i <= 11; ++i)
    // {
    //     for (int j = 0; j <= 11; ++j)
    //     {
    //         printf("%d", map[i][j]);
    //     }
    //     printf("\n");
    // }

    while (1)
    {
        if (fa == co)
        {
            printf("%d", cnt);
            break;
        }
        if (vis[fa.x][fa.y][co.x][co.y][fa.dir][co.dir]++ == 1)
        {
            printf("0");
            return 0;
        }
        ++cnt;
        ++fa;
        ++co;
    }

    return 0;
}
2024/12/20 20:59
加载中...