显示原始代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<ll, pair<ll, ll> > > ps;
bool cmpx(pair<ll, pair<ll, ll> > p1, pair<ll, pair<ll, ll> > p2) {
return p1.second.first < p2.second.first;
}
bool cmpy(pair<ll, pair<ll, ll> > p1, pair<ll, pair<ll, ll> > p2) {
return p1.second.second < p2.second.second;
}
int main() {
ios::sync_with_stdio(false);
ll n;
cin >> n;
ps.resize(n);
for (ll i = 0; i < n; ++i) {
ll x, y;
cin >> x >> y;
ps[i].first = i + 1;
ps[i].second.first = x - y;
ps[i].second.second = x + y;
}
if (n % 2) {
sort(ps.begin(), ps.end(), cmpx);
ll x0 = ps[n / 2].second.first;
sort(ps.begin(), ps.end(), cmpy);
ll y0 = ps[n / 2].second.second;
auto p = ps.begin();
for (auto p1 = ps.begin(); p1 != ps.end(); ++p1) {
if (abs((*p1).second.first - x0) + abs((*p1).second.second - y0) <
abs((*p).second.first - x0) + abs((*p).second.second - y0))
p = p1;
}
ps.erase(p);
--n;
}
sort(ps.begin(), ps.end(), cmpx);
sort(ps.begin(), ps.begin() + n / 2, cmpy);
sort(ps.begin() + n / 2, ps.end(), cmpy);
cout << n / 2 << endl;
for (int i = 0, j = n - 1; i < j; ++i, --j) {
cout << ps[i].first << ' ' << ps[j].first << endl;
}
}