html5網(wǎng)站下載建站模板哪個(gè)好
1.學(xué)會(huì)了原來(lái)字符串也有比較方法,也就是字符串987 > 98 等等,可以解決拼最大數(shù)問(wèn)題
題目鏈接:5.拼數(shù) - 藍(lán)橋云課 (lanqiao.cn)
2.今天又復(fù)習(xí)了一下bfs,感覺(jué)還是很不熟練,可能是那個(gè)過(guò)程我些許有點(diǎn)不熟悉,準(zhǔn)備再看看bfs然后自己總結(jié)一下。
bfs做題步驟
1,定義好結(jié)構(gòu)體,數(shù)組,標(biāo)記數(shù)組
2,定義好方向數(shù)組
3,定義好出發(fā)點(diǎn)和結(jié)束點(diǎn)
4,在用結(jié)構(gòu)體定義好起始點(diǎn)給隊(duì)列,起始點(diǎn)的標(biāo)記數(shù)組設(shè)置為1。
5,while循環(huán),條件是隊(duì)列不能為空
6,里面先寫結(jié)束條件,結(jié)束條件就是當(dāng)前走的點(diǎn)走到了結(jié)束點(diǎn)
7,然后for循環(huán)方向數(shù)組,重新定義當(dāng)前的x,y,step,讓step + 1。讓當(dāng)前的x,y的標(biāo)記數(shù)組變成1。
8,然后彈出來(lái)。
標(biāo)準(zhǔn)的bfs模板代碼如下
# include <iostream>
# include <queue>
using namespace std;
int a[110][110];
bool vis[110][110];
struct Type{int x;int y;int step;
};int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};int main()
{int n, m, x1, x2, y1, y2;queue<Type> q1;cin>>n>>m;for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){cin>>a[i][j];}}cin>>x1>>y1>>x2>>y2;Type start;start.x = x1;start.y = y1;start.step = 0;q1.push(start);vis[x1][x2] = 1;int flag = 0;while(!q1.empty()){int x = q1.front().x, y = q1.front().y;if(x == x2 && y == y2){flag = 1;cout<<q1.front().step<<endl;break;}for(int k = 0; k < 4; k++){int tx, ty;tx = q1.front().x + dx[k];ty = q1.front().y + dy[k];if(a[tx][ty] == 1 && vis[tx][ty] == 0){Type temp;temp.x = tx;temp.y = ty;temp.step = q1.front().step + 1;q1.push(temp);vis[tx][ty] = 1;}}q1.pop();}if(flag == 0){cout<<-1<<endl;}return 0;
}
題目鏈接:7.走迷宮 - 藍(lán)橋云課 (lanqiao.cn)