bfs + 路徑記錄:
/*
*problem id: hdu 1026
* author id: fuqiang11
* time: 2013-07-17
* algorithm: bfs
* status: (accept)
*/
#include #include #include using namespace std;
#define inf 0x3f3f3f3f
#define maxn 103
char map[maxn][maxn];
int n,m;
int value[maxn][maxn]; //記錄步數
struct point
st,ed,a,pre[maxn][maxn]; //pre 記錄前乙個點
int xx = ;
int yy = ;
void bfs(int x,int y)
}else
}} }
}void prin_pre(int i, int j) //輸出路徑
}}int main()
else
puts("finish");
}}
dfs超時(明顯的,n、m <= 100,我居然還這樣做的!)
如果n.m較小的話,還是能承受的,比如10、20、30
超時的**先掛這吧,以示警醒;
/*
*problem id: hdu 1026
* author id: fuqiang11
* time: 2013-07-16
* algorithm: dfs
* status: (runtimeerror)
*/#include #include #include #include #define inf 0x3f3f3f3f
using namespace std;
#define maxn 103
char map[maxn][maxn];
int v[maxn][maxn];
struct point
pre[maxn][maxn];
int n,m;
int xplus = ;
int yplus = ;
void dfs(int x,int y)
} if(map[xx][yy]>='1' && map[xx][yy]<='9')
} }}
void prin_pre(int i, int j) //輸出路徑 }}
int main()
else
puts("finish");
}}
HDU1026(BFS求最短路徑並記錄)
一.題意 英雄去救公主,起點 0,0 終點 row 1,col 1 x 不能走,遇到數字停下來打怪,數字多少就要打多少秒,求最快到達時間。二.解題思路 看結構體怎麼定義的就直接知道我怎麼記錄路徑的,記得路徑的陣列要開大一些。三.ac include include include include u...
HDU1026 BFS 優先佇列 路徑儲存
剛開始做bfs專題時遇到它,因為路徑儲存放棄了 現在做,剛開始各種wa。後來加了個優先佇列,就ac了。額。include include include include include include include include include include includeusing name...
hdu 1026 優先佇列 路徑儲存
include include include using namespace std define maxsize 105 char map maxsize maxsize bool hash maxsize maxsize int n,m struct node bool operator no...