P1443 馬的遍歷

2022-07-24 06:15:12 字數 631 閱讀 7906

有乙個n*m的棋盤(1一行四個資料,棋盤的大小和馬的座標

輸出格式:

乙個n*m的矩陣,代表馬到達某個點最少要走幾步(左對齊,寬5格,不能到達則輸出-1)

輸入樣例#1:複製

3 3 1 1

輸出樣例#1:複製

0    3    2    

3 -1 1

2 1 4

#includeusing

namespace

std;

struct

pos;

int mark[405][405],dx= ,dy= ,n,m;

queue

q;void bfs(int sx,int

sy));

mark[sx][sy]=0

;

while(!q.empty())

);mark[tx][ty]=mark[x][y]+1

; }

}}int

main()

cout

<}

return0;

}

P1443 馬的遍歷

題目描述 有乙個n m的棋盤 1輸入輸出格式 輸入格式 一行四個資料,棋盤的大小和馬的座標 輸出格式 乙個n m的矩陣,代表馬到達某個點最少要走幾步 左對齊,寬5格,不能到達則輸出 1 輸入樣例 1 3 3 1 1 輸出樣例 1 0 3 2 3 1 1 2 1 4bfs題,遍歷一下所有的位置 inc...

p1443馬的遍歷

就是一道很簡單的bfs,我為了練習一下queue型別的函式,第一次沒有用陣列模擬,直接上 這道題有乙個特殊的輸出,就是輸出寬五行,學習一下。include include include include include using namespace std int n,m const int ma...

P1443 馬的遍歷

有乙個n m的棋盤 1一行四個資料,棋盤的大小和馬的座標 乙個n m的矩陣,代表馬到達某個點最少要走幾步 左對齊,寬5格,不能到達則輸出 1 331 1032 3 11 214 include include include include using namespace std int chess...