#include using namespace std; using ll = long long; #define TARGET 500000000000000000LL inline ll scoreCal(ll a0, ll a1, ll b0, ll b1) { ll newA = (a0 + a1) / 2; ll newB = (b0 + b1) / 2; ll score = max( abs(TARGET-newA), abs(TARGET-newB)); return score; } inline ll scoreCal2(ll a0, ll b0) { return max(abs(TARGET-a0), abs(TARGET-b0)); } int main() { // スタート時点のタイムスタンプ取得 auto start_time = std::chrono::high_resolution_clock::now(); int N; cin >> N; vector A(N), B(N); for (int i=0; i> A[i] >> B[i]; } vector Aorg, Borg; Aorg = A; Borg = B; #if 1 // 基準スコア作成(1固定で他のカードとペアリング) vector> ret; for (int i=0; i<50; ++i) { int u = 0; int v = 0; ll minScore = scoreCal2(A[0], B[0]); for (int j=1; j> ret1; int u; int v; // 終了時点のタイムスタンプ取得 auto end_time = std::chrono::high_resolution_clock::now(); // 経過時間の計算 auto elapsed_time = std::chrono::duration_cast(end_time - start_time).count(); srand(static_cast(time(NULL))); while(true) { //count++; A.clear(); B.clear(); ret1.clear(); A = Aorg; B = Borg; for (int i=0; i<50; ++i) { u = rand()%N; v = rand()%N; while (u == v) { v = rand()%N; } ret1.push_back(make_pair(u+1, v+1)); ll newA = (A[u] + A[v]) / 2; ll newB = (B[u] + B[v]) / 2; A[u] = A[v] = newA; B[u] = B[v] = newB; } ll tmpScore = scoreCal2(A[0], B[0]); if (tmpScore < minScore) { minScore = tmpScore; ret.clear(); ret = ret1; //minA = A[0]; //minB = B[0]; } // 終了時点のタイムスタンプ取得 end_time = std::chrono::high_resolution_clock::now(); // 経過時間の計算 elapsed_time = std::chrono::duration_cast(end_time - start_time).count(); // 経過時間と制限時間の比較 int time_limit = 970; // 制限時間 if (elapsed_time > time_limit) { break; } } //cout << "minScore : " << minScore << endl; //cout << count << endl; //cout << minA << " " << minB << endl; cout << ret.size() << endl; for (auto x : ret) { cout << x.first << " " << x.second << endl; } return 0; }