-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2194.cpp
75 lines (74 loc) · 1.76 KB
/
2194.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#define MAX 100000000
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<utility>
#include<math.h>
#include<memory.h>
#include<stack>
#include<string>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef queue<pair<int, int>> qii;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
int n, m, a, b, k;
int map[501][501];
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
int visit[501][501];
qii q;
bool check(int x, int y) {
for (int j = 0; j < a; j++) {
for (int l = 0; l < b; l++) {
if (map[x + j][y + l] == 1) {
return false;
}
}
}
return true;
}
void bfs() {
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
if (map[x][y] == 3) {
return;
}
for (int i = 0; i < 4; i++) {
int mx = x + dx[i];
int my = y + dy[i];
if (0 >= mx || mx + a - 1 > n || 0 >= my || my + b - 1 > m) continue;
if (visit[mx][my]) continue;
if (check(mx, my)) {
visit[mx][my] = visit[x][y] + 1;
q.push({ mx,my });
}
}
}
}
int main() {
cin.tie(NULL); ios_base::sync_with_stdio(false);
cin >> n >> m >> a >> b >> k;
for (int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
map[x][y] = 1;
}
int s, e;
cin >> s >> e;
map[s][e] = 2; //½ÃÀÛ
visit[s][e] = 1;
q.push({ s,e });
cin >> s >> e;
map[s][e] = 3; //¸ñÀûÁö
bfs();
cout << visit[s][e] - 1;
return 0;
}