全WA求助
查看原帖
全WA求助
180059
return_dirt楼主2021/12/22 19:43

准确的说是 样例过了,第一个点和样例输出一样,但是评测结果是WA……

刚才测试了一下直接把第一个点的输出打出去也WA了。

求大佬讲解一下

#include <cstdio>
#include <iostream>
#define SIZE 2000

int n,m;
char c;

bool bl[SIZE][SIZE];

int tx[4]={0,-1,0,1};
int ty[4]={1,0,-1,0};

struct POINT{
    int x;
    int y;
};
POINT start;

bool vis[SIZE][SIZE];
POINT lastVis[SIZE][SIZE];
bool DGED = 0;

void dfs(int x,int y,int totx,int toty)
{
    if(DGED)return;
    if(vis[x][y])
    {
        if(lastVis[x][y].x == totx && lastVis[x][y].y == toty)
        {
            return;
        }
        else
        {
            DGED = 1;
            return;
        }
    }
    else
    {
        vis[x][y] = 1;
        lastVis[x][y].x = totx;
        lastVis[x][y].y = toty;
        for(int i=0;i<4;i++)
        {
            int tox = (x+tx[i]+n)%n;
            int toy = (y+ty[i]+m)%m;
            if(!bl[tox][toy])
            dfs(tox,toy,totx+tx[i],toty+ty[i] );
        }
    }
}


int main()
{
//    freopen("P1363_1.in","r",stdin);
//    freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&m)!=EOF)
{

    DGED = 0;
    getchar();
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            scanf("%c",&c);
//            printf("get %c ",c);
            bl[i][j] = 0;
            vis[i][j]= 0;

            if( c == '#' )bl[i][j] = 1;
            if( c == 'S' )
            {
                start.x = i;
                start.y = j;
            }
        }
        getchar();
    }
    dfs(start.x,start.y,start.x,start.y);
    if(DGED)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
}
return 0;
}

2021/12/22 19:43
加载中...