4 4 2 PLLP PPLP PPPP PLLP
#include#include #include #include #include const int N = 200; using namespace std; int mapp[N][N]; bool vis[N][N][N]; int n,m,D; int mv[4][2] = {{1,0},{0,-1},{0,1},{-1,0}}; struct node { int x,y,ans,d; }; int st(int x,int y) { return x*y; } int BFS(int D) { node f,t; queue q; memset(vis,0,sizeof(vis)); f.x = 0; f.y = 0; f.ans = 0; f.d = D; q.push(f); vis[f.x][f.y][f.d] = true; while(!q.empty()) { t = q.front(); if(t.x==n-1 && t.y==m-1) return t.ans; q.pop(); for(int i = 0;i < 4;i++) //走路 { f.x = t.x + mv[i][0]; f.y = t.y + mv[i][1]; if(0 <= f.x && f.x =1;num--)//找當前最優路線,盡可能的飛的最遠 { f.x = t.x + st(mv[i][0],num); f.y = t.y + st(mv[i][1],num);//注意平原陸地都可以飛,但是起飛點和落地點必須都是平原 if(0 <=f.x && f.x
5 5 4
PPPPP
PPPPP
LLLLL
LLLLL
LLLLL
impossible
6 6 5
PPPPPL
PLPLPL
LLLLLL
PPPPPP
PPPPPP
PPPPPP
6
1 1 1
P
0
3 3 3
PPP
PPP
PPP
3
4 4 4
PLPL
LPLP
PPPP
LLLP
4
8 8 1
PPPPPPPP
PLPLPLPL
LLLLLLLL
PPPPPPPP
PPPPPPPP
PPPPPPPP
PPPPPPPP
PPPPPPPP
impossible