Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <bits/stdc++.h>
- using namespace std;
- const int INF = 1e9;
- int main() {
- int n, m, k, bx, by, ex, ey, nx, ny, w = 0;
- cin >> n >> m >> k >> bx >> by;
- vector <pair <int,int> > a(m);
- vector<pair <int, int> > res;
- for (int i = 0; i < m; ++i) {
- cin >> a[i].first >> a[i].second;
- }
- vector<int> dx = {-2, -1, 1, 2, 2, 1, -1, -2}, dy = {1, 2, 2, 1, -1, -2, -2, -1};
- vector<vector<int> > dist(n, vector<int>(n, INF));
- dist[bx][by] = 0;
- queue<pair<int, int> > q;
- q.push({bx, by});
- while (!q.empty()) {
- ex = q.front().first;
- ey = q.front().second;
- q.pop();
- for (int i = 0; i < 8; ++i) {
- if (ex + dx[i] < 0 || ey + dy[i] < 0 || ex + dx[i] >= n || ey + dy[i] >= n) continue;
- for(auto j : a){
- if(ex + dx[i] == j.first && ey + dy[i] == j.second) continue;
- }
- nx = ex + dx[i];
- ny = ey + dy[i];
- dist[nx][ny] = dist[ex][ey] + 1;
- if(dist[nx][ny] == k){
- res.push_back({nx, ny});
- }
- q.push({nx, ny});
- }
- }
- cout << res.size();
- for(auto i : res){
- cout << i.first << ' ' << i.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement