#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;
}
201604-4--------------游戏
最新推荐文章于 2022-03-07 16:42:43 发布