#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int x,y,step;
};
const int N = 110, M = 310;
bool st[N][N][M];
int n, m, t;
int r, c, a, b;
void bfs(){
queue<node> q;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
q.push({1, 1, 0});
while(!q.empty()){
auto t = q.front();
q.pop();
int x = t.x, y = t.y, step = t.step;
if(x == n && y == m){
cout << step;
return ;
}
for(int i = 0; i < 4; i ++){
int xx = x + dx[i], yy = y + dy[i], ss = step + 1;
if(xx > 0 && xx <= n && yy > 0 && yy <= m && st[xx][yy][ss] == 0){
q.push({xx, yy, ss});
st[xx][yy][ss] = true;
}
}
}
}
int main(){
cin >> n >> m >> t;
while(t--){
cin >> r >> c >> a >> b;
for(int i = a; i <= b; i ++){
st[r][c][i] = true;
}
}
bfs();
return 0;
}
05-16
241
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交