#include<bits/stdc++.h> usingnamespace std; typedeflonglong ll; typedefdouble db; constint N = 1e5 + 10; const ll mod = 1e9 + 7;
int dx[] = { 0,0,-1,1 }; int dy[] = { -1,1,0,0 };
voiddeer() { int n; cin >> n; vector<pair<int, int>> a(n); for (auto& [x, y] : a) cin >> x >> y; //坐标存在a中
set<pair<int, int>> st(a.begin(), a.end()); //坐标copy到st中 map<pair<int, int>, pair<int, int>> ans; //键坐标对应找的的答案坐标为值 queue<pair<int, int>> q; for (auto [x, y] : a) //取a中坐标 { for (int i = 0;i < 4;i++) { int nx = x + dx[i], ny = y + dy[i]; if (st.count({ nx,ny })) continue; //存在则不可用,继续找下一个 ans[{x, y}] = { nx,ny }; //可用,则push为答案 q.push({ x,y }); //找到答案后推进去 break; } }
while (!q.empty()) { int x = q.front().first, y = q.front().second; q.pop(); for (int i = 0;i < 4;i++) { int nx = x + dx[i], ny = y + dy[i]; if (!st.count({ nx,ny }) || ans.count({ nx,ny })) continue; //排除不是原点或者已记录为答案的点,继续寻找,把原坐标的对应答案找齐 ans[{nx, ny}] = ans[{x, y}]; //记录已经找过的或原坐标 q.push({ nx,ny }); //在移动点基础上再寻找 } }
for (auto [x, y] : a) { auto it = ans[{x, y}]; cout << it.first<<" "<<it.second << "\n"; } return; }