蒟蒻求助!!!!!!!!!洛谷编译失败
  • 板块P1443 马的遍历
  • 楼主Samsgc
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/8/8 23:41
  • 上次更新2024/8/9 09:01:03
查看原帖
蒟蒻求助!!!!!!!!!洛谷编译失败
616347
Samsgc楼主2024/8/8 23:41

下面是代码部分

#include<bits/stdc++.h>
/*#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>*/
using namespace std;
int n,m,tx,ty;
int ans[309][309];
int move[10][5]={{1,2},{2,1},{1,-2},{2,-1},{-1,-2},{-2,-1},{-1,2},{-2,1}};
struct horse
{
   int x,y;
};
queue<horse> Q; 
int main()
{
   cin>>n>>m>>tx>>ty;
   memset(ans,-1,sizeof(ans));
   horse tmp={tx,ty};
   ans[tx][ty]=0;
   Q.push(tmp);
   while(!Q.empty())
   {
   	horse nnow=Q.front();
   	Q.pop();
   	for(int i=0;i<8;i++)
   	{
   		int nx=nnow.x+move[i][0],ny=nnow.y+move[i][1];
   		if(nx<1||nx>n||ny<1||ny>m||ans[nx][ny]!=-1)continue;
   		int d=ans[nnow.x][nnow.y];
   		ans[nx][ny]=d+1;
   		horse tmp={nx,ny};
   		Q.push(tmp);
   	}
   }
   for(int i=1;i<=n;i++,puts(""))
       for(int j=1;j<=m;j++)
           printf("%-5d",ans[i][j]);
   return 0;
}
2024/8/8 23:41
加载中...