1.注意輸出格式 printf("-5d")代表左對齊,空5格。
2.team陣列要開的大點。。否則會wa或者re一些點。
3.結構體來存team陣列,最後要判斷到不了輸出-1
好像也沒啥了。。。
#include#include#include#include#include#includeusing namespace std;
const int maxn=10010;
const int dx[8]=;
const int dy[8]=;
int n,m,x,y;
struct h
;int a[maxn][maxn];
bool b[maxn][maxn];
h team[maxn*4];
int s=0,t=0;
void bfs(int x,int y)
} }for(int i=1;i<=n;i++)
}} return ;
}int main()
cout<} return 0;
}
洛谷題解 P1443 馬的遍歷
洛谷,有乙個 n m 的棋盤 1 n,m 400 在某個點上有乙個馬,要求你計算出馬到達棋盤上任意乙個點最少要走幾步?一行四個資料,棋盤的大小和馬的座標。乙個 n m 的矩陣,代表馬到達某個點最少要走幾步 左對齊,寬 5 格,不能到達則輸出 1 3 3 1 10 3 2 3 1 1 2 1 4 告訴...
洛谷 P1443 馬的遍歷
題目概述 有乙個n m的棋盤 1 解題思路 使用廣搜,注意地圖邊界和馬跳的方向即可。可以採用for代替8個if來減少要碼的字。注意棧的讀寫。時間複雜度 o n m 空間複雜度 o n m 源程式 const d array 1.2,1.8 of longint 2,2,1,1,1,1,2,2 1,1...
洛谷 P1443馬的遍歷
有乙個n m的棋盤 1輸入格式 一行四個資料,棋盤的大小和馬的座標 輸出格式 乙個n m的矩陣,代表馬到達某個點最少要走幾步 左對齊,寬5格,不能到達則輸出 1 輸入樣例 1 複製3 3 1 1 輸出樣例 1 複製0 3 2 3 1 1 2 1 4 include include include i...