显示原始代码
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
}
const int maxn = 1e5 + 5;
int n;
struct pt {
int id, x, y;
} t[maxn];
vector<int> W[4];
bool cmp(const pt a, const pt b) { return a.x < b.x; }
bool cmpp(const pt a, const pt b) { return a.y < b.y; }
int main() {
read(n);
for (int i = 1; i <= n; ++i) {
read(t[i].x), read(t[i].y), t[i].id = i;
t[i].x = t[i].x + t[i].y;
t[i].y = t[i].x - t[i].y;
}
int X, Y;
if (n & 1) {
sort(t + 1, t + n + 1, cmp);
int X = t[n / 2 + 1].x;
sort(t + 1, t + n + 1, cmpp);
int Y = t[n / 2 + 1].y;
int p = 1;
for (int i = 2; i <= n; ++i)
if (abs(t[p].x - X) + abs(t[p].y - Y) > abs(t[i].x - X) + abs(t[i].y - Y))
p = i;
swap(t[p], t[n]);
--n;
}
sort(t + 1, t + n + 1, cmp);
sort(t + 1, t + n / 2 + 1, cmpp);
sort(t + n / 2 + 1, t + n + 1, cmpp);
printf("%d\n", n / 2);
for (int i = 1; i <= n / 2; ++i) printf("%d %d\n", t[i].id, t[n - i + 1].id);
return 0;
}