社区讨论

求解下载下来数据本地测试都对,但是wa声一片啊

P1443马的遍历参与者 3已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@mi6ydrr7
此快照首次捕获于
2025/11/20 12:50
4 个月前
此快照最后确认于
2025/11/20 12:50
4 个月前
查看原帖
以下是代码 #include #include using namespace std; int board[201][201],step[201][201]; int o[8][2]={{-1,-2},{-1,2},{1,-2},{1,2},{-2,-1},{-2,1},{2,-1},{2,1}}; queueh; queuel; int n,m,starth,startl; void bfs(int ,int); int main() { scanf("%d%d%d%d",&n,&m,&starth,&startl); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { board[i][j]=0; step[i][j]=0; }//board与step数组初始化 bfs(starth,startl); printf("\n\n"); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(step[i][j]==0) { if(i==starth and j==startl) printf("0 "); else printf("-1 "); } else printf("%-5d ",step[i][j]); } printf("\n"); } return 0; } void bfs(int x,int y) { board[x][y]=1; h.push(x); l.push(y); int q1,q2; while(h.size()!=0) { for(int i=0;i<=7;i++) { q1=h.front()+o[i][0]; q2=l.front()+o[i][1]; if(board[q1][q2]==0 and q1>=1 and q1<=n and q2>=1 and q2<=m)//是否遍历过以及边界条件!! { //printf("%d %d %d %d \n",q1,q2,o[i][0],o[i][1]); board[q1][q2]=1;//打标记 h.push(q1); l.push(q2); step[q1][q2]=step[h.front()][l.front()]+1; } } h.pop(); l.pop(); } return ; }

回复

5 条回复,欢迎继续交流。

正在加载回复...