为什么会MLE?
查看原帖
为什么会MLE?
1031931
14425aab楼主2024/3/27 23:24
#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

struct node
{
    int x,y;
    int step=0;
};

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

queue<node> q;

int n,m,x,y;

int map[410][410];

bool ok(int x,int y)
{
    if(x<=0||y<=0||x>n||y>m)
    return false;
    if(map[x][y]!=-1)
    return false;
    return true;
}

int main()
{
    memset(map,-1,sizeof map);
    cin>>n>>m>>x>>y;
    struct node start;
    start.x=x;
    start.y=y;
    start.step=0;
    map[1][1]=true;
    q.push(start);
    while(!q.empty())
    {
        struct node top=q.front();
        q.pop();
        map[top.x][top.y]=top.step;
        for(int i=0;i<8;i++)
        {
            if(ok(top.x+dx[i],top.y+dy[i]))
            {
                struct node New;
                New.x=top.x+dx[i];
                New.y=top.y+dy[i];
                New.step=top.step+1;
                q.push(New);
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            printf("%d    ",map[i][j]);
        }
        cout<<endl;
    }
    return 0;
}
2024/3/27 23:24
加载中...