显示原始代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<ll, pair<ll, ll>> ps[100000];
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;
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, ps + n, cmpx);
ll x0 = ps[(n - 1) / 2].second.first;
sort(ps, ps + n, cmpy);
ll y0 = ps[(n - 1) / 2].second.second;
auto p = ps[0];
for (auto& p1 : ps) {
if (abs(p.second.first - x0) + abs(p.second.second - y0) >
abs(p1.second.first - x0) + abs(p1.second.second - y0))
p = p1;
}
sort(ps, ps + (n - 1) / 2, cmpx);
sort(ps + (n - 1) / 2 + 1, ps + n, cmpx);
cout << (n - 1) / 2 << endl;
bool flag = true;
for (int i = 0, j = n - 1; i < j; ++i, --j) {
if (flag) {
if (ps[i] == p) {
++j;
flag = false;
continue;
} else if (ps[j] == p) {
--i;
flag = false;
continue;
}
}
cout << ps[i].first << ' ' << ps[j].first << endl;
}
}
else {
sort(ps, ps + n, cmpx);
sort(ps, ps + n / 2, cmpy);
sort(ps + n / 2, ps + n, cmpy);
cout << n / 2 << endl;
for (int i = 0, j = n - 1; i < j; ++i, --j) {
cout << ps[i].first << ' ' << ps[j].first << endl;
}
}
}