题目链接:Rescue
进度落下的太多了,哎?(???)?,渣渣我总是埋怨进度比别人慢。。。为什么不试着改变一下捏。。。。
开始以为是水题,想敲一下练手的,后来发现并不是一个简单的搜索题,BFS做肯定出事。。。后来发现题目里面也有坑
题意是从r到a的最短距离,“.”相当时间单位1,“x”相当时间单位2,求最短时间
HDU 搜索课件上说,这题和HDU1010相似,刚开始并没有觉得像剪枝,就改用 双向BFS 0ms 一Y,爽!
网上查了一下,神牛们竟然用BFS+优先队列。。。顿悟
vc+089amzPWjrL340NC89NamoaM8L3A+CjxwPsfDwcvSu8/Co6xCRlMgJiM0Mzsg08XPyLbTwdAgICAxNW1zICDSu1mjrM/g0MXI57n71NphbnO1xLTmtKLJz9PFu6/Su8/Co6yw0b3P0KG1xGFuc9PFz8i0orTmo6wwbXO63Mfhy8k8L3A+CjxwPjxpbWcgc3JjPQ=="https://www.cppentry.com/upload_files/article/49/1_tqrme__.jpg" alt="\">
送一特殊数据:
3 3
.a.
x#.
.r.
打印 4
BFS + 优先队列 代码如下
#include
#include
#include
#include
#include
const int N = 210; using namespace std; struct node { int x, y,ans; friend bool operator <(const node &a,const node &b) { return a.ans>b.ans; } }; int n, m; char ma[N][N]; bool vis[N][N]; int sx, sy; int mv[4][2] = {{-1,0},{0,1},{0,-1},{1,0}}; void BFS(int sx,int sy) { priority_queue
q; node f, t; f.x = sx, f.y = sy, f.ans = 0; vis[sx][sy] = true; q.push(f); while(!q.empty()) { t = q.top(); if(ma[t.x][t.y]=='r') { cout<
双向BFS
#include
#include
#include
#include
#include
const int N = 210; using namespace std; int mapp[N][N]; int vis[N][N]; struct node{ int x,y; }; int n,m; char ma[210][210]; int mv[4][2] = {{1,0},{0,1},{0,-1},{-1,0}}; int dis[N][N]; void BFS(int sx,int sy,int ex,int ey) { queue
q; node t,f; memset(vis,0,sizeof(vis)); memset(dis,0,sizeof(dis)); f.x = sx; f.y = sy; t.x = ex; t.y = ey; vis[sx][sy] = 1; vis[ex][ey] = 2; q.push(f); q.push(t); while(!q.empty()) { t = q.front(); 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
渣渣