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

P1443 马的遍历

希望更丰富的展现?使用Markdown
by _FILARET_ @ 2018-10-12 19:29:44


@[deadpool123](/space/show?uid=84121) 抱歉 以为会自动格式弄好,我重新发帖
by 旅人杜 @ 2018-10-12 19:31:49


``` include<cstdio> include<queue> 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}}; queue<int>h; queue<int>l; 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 ; } ```
by 外太空 @ 2018-10-12 19:33:01


@[旅人杜](/space/show?uid=96934) ```cpp #include<cstdio> #include<queue> 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}}; queue<int>h; queue<int>l; 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)//是否遍历过以及边界条件!! { board[q1][q2]=1;//打标记 h.push(q1); l.push(q2); step[q1][q2]=step[h.front()][l.front()]+1; } } h.pop(); l.pop(); } return ; } ```
by 旅人杜 @ 2018-10-12 19:35:08


@[deadpool123](/space/show?uid=84121) 麻烦看一下
by 旅人杜 @ 2018-10-12 19:35:23


|