显示原始代码
#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 = 1e6 + 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);
X = t[n / 2].x;
sort(t + 1, t + n + 1, cmpp);
Y = t[n / 2].y;
for (int i = 1; i <= n; ++i)
if (t[i].x <= X && t[i].y <= Y)
W[0].push_back(t[i].id);
else if (t[i].x > X && t[i].y > Y)
W[1].push_back(t[i].id);
else if (t[i].x <= X && t[i].y > Y)
W[2].push_back(t[i].id);
else
W[3].push_back(t[i].id);
printf("%d\n", n / 2);
for (int i = 0; i < W[0].size(); ++i) printf("%d %d\n", W[0][i], W[1][i]);
for (int i = 0; i < W[2].size(); ++i) printf("%d %d\n", W[2][i], W[3][i]);
return 0;
}