#include // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; const ll INF=4e18; #define debug1(a) { cerr<<#a<<":"< T random_choice(vector &vec) { return vec[engine() % vec.size()]; } bool anneal_accept(double new_score, double old_score, double cur_time, double begin_time, double end_time, double begin_temp, double end_temp) { const int ANNEAL_RND = 1e8; const double ANNEAL_EPS = 1e-6; double temp = (begin_temp * (end_time - cur_time) + end_temp * (cur_time - begin_time)) / (end_time - begin_time); return (exp((new_score - old_score) / temp) > double(engine() % ANNEAL_RND) / ANNEAL_RND + ANNEAL_EPS); } } // namespace marathon const int OPLIMIT = 50; const int N = 45; const ll F17 = 500000000000000000; card_t INIT_AB[N]; double evaluate(card_t x) { double da = abs(x.a - F17); double db = abs(x.b - F17); return max(da, db) * 100 + min(da, db); } double evaluate2(card_t x, card_t dest) { double da = abs(x.a - dest.a); double db = abs(x.b - dest.b); return max(da, db) * 100 + min(da, db); } void rec(vector &ops, vector &used, pair> &best_result, card_t used_total, card_t target, int lastind, int maxops, vector &now_cards) { if (ops.size() >= 1) { auto new_zero = avg(used_total, now_cards[lastind]); double e = evaluate(new_zero); if (e < best_result.first) { best_result = {e, ops}; } } if (ops.size() >= maxops) { return; } for (int j = 0; j < N; j++) { if (used[j]) continue; used[j] = true; ops.push_back(j); card_t nxt_used_total = (used_total.a <= 0) ? now_cards[j] : avg(now_cards[j], used_total); rec(ops, used, best_result, nxt_used_total, target, lastind, maxops, now_cards); ops.pop_back(); used[j] = false; } } void do_op(int i, int j, vector &now_cards, vector> &result) { card_t avg_ = avg(now_cards[i], now_cards[j]); now_cards[i] = avg_; now_cards[j] = avg_; result.push_back({i, j}); } void output(vector> &result) { cout << result.size() << endl; for (auto p : result) { cout << p.first + 1 << " " << p.second + 1 << endl; } } vector anneal(int siz, vector &now_cards) { vector ops; auto avgscore = [&]() { int m = ops.size(); ll a = 0; ll b = 0; if (ops.size() == 1) { return -evaluate(avg(now_cards[ops.back()], now_cards[0])); } else { for (int i = 0; i < m; i++) { if (i == m - 1) { a += now_cards[ops[i]].a / (2 << (m - 2)); b += now_cards[ops[i]].b / (2 << (m - 2)); } else { a += now_cards[ops[i]].a / (2 << i); b += now_cards[ops[i]].b / (2 << i); } } return -evaluate({(a + now_cards[0].a) / 2, (b + now_cards[0].b) / 2}); } }; pair> bestresult = {-1e50, {}}; for (int loop = 0; loop < 100; loop++) { vector used(N); double bs = -1; for (int it = 0; it < siz; it++) { pair best = {-1e50, -1}; for (int u = 1; u < N; u++) { if (used[u]) continue; ops.push_back(u); pair now = {avgscore() * marathon::uniform(1.0, 2.0), u}; best = max(now, best); ops.pop_back(); } { bs = best.first; used[best.second] = true; ops.push_back(best.second); } } if (bestresult.first < bs) { bestresult = {bs, ops}; debug1(bestresult.first); } ops.clear(); } return bestresult.second; } void solve() { vector now_cards(N); for (int i = 0; i < N; i++) { now_cards[i] = INIT_AB[i]; } vector> result; int it = 0; while (result.size() <= OPLIMIT - 10) { it++; auto ops = anneal(25, now_cards); auto work_cards = now_cards; auto work_result = result; int m = ops.size(); for (int i = m - 1; i >= 1; i--) { do_op(ops[i], ops[i - 1], work_cards, work_result); } do_op(0, ops[0], work_cards, work_result); if (evaluate(work_cards[0]) < evaluate(now_cards[0])) { now_cards = work_cards; result = work_result; } else { break; } debug2(result.size(), now_cards[0]); } output(result); } int main() { marathon::marathon_init(); int n; cin >> n; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; INIT_AB[i] = card_t{a, b}; } solve(); return 0; }