日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hdu1072广搜

發(fā)布時間:2024/4/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hdu1072广搜 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

  題意:0不能走,1可以走,2起始位置,3中點,4時間變成6.初始時間為6 ?走到終點或者4時時間不能為0.問能否走到終點和 到終點的最短距離。

反正時間就是6 ,每個點可以重復走,隨便走就行。剪紙 就是 經(jīng)過4這個點只要經(jīng)過一次,第二次經(jīng)過這個點的路程一定比第一次經(jīng)過的長 ?并且都重置了時間。

#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <vector> #include <map> #include <string> #include <iostream> using namespace std; const int maxn = 8; int Map[maxn][maxn]; int n,m; int bx,ex,by,ey; int dx[]={0,0,-1,1}; int dy[]={-1,1,0,0}; struct Node {int x;int y;int time;int dist; }; int gao(int x,int y) {if(x>=0&&x<n&&y>=0&&y<m&&Map[x][y]) return 1;return 0; } int dfs() {queue<Node> q;Node t ; t.x= bx;t.y=by; t.time= 6; t.dist= 0;q.push(t);while(!q.empty()){Node cur=q.front(); q.pop();if(cur.x==ex&&cur.y==ey) return cur.dist;if(cur.time<=1) continue;for(int i=0;i<4;i++){int xx= cur.x+dx[i];int yy=cur.y+dy[i];if(!gao(xx,yy)) continue;Node gg;gg.x= xx ;gg.y= yy;gg.dist= cur.dist+1;gg.time = cur.time- 1;if(Map[xx][yy]==4){Map[xx][yy]=0;gg.time = 6;}q.push(gg);}}return -1; }int main() {int Icase;cin>>Icase;while(Icase--){cin>>n>>m;for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%d",&Map[i][j]);if(Map[i][j] ==2) bx = i ,by = j;if(Map[i][j]==3) ex = i ,ey = j;}}printf("%d\n",dfs());}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/yigexigua/p/3968767.html

總結(jié)

以上是生活随笔為你收集整理的Hdu1072广搜的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。