#include #include #include #include #include using namespace std; const long long Target = 500000000000000000LL; long long N; long long A[59]; long long B[59]; long long Order[59]; long long BestOrder[59]; long long GetScore() { long long TotalScore = (A[1] >> (N - 1)); for (int i = 1; i <= N - 1; i++) TotalScore += (A[Order[i]] >> (N - i)); return abs(Target - TotalScore); } long double Randouble() { double s = 0.0, t = 1.0; for (int i = 0; i < 3; i++) { t /= 1024.0; s += 1.0 * (rand() % 1024) * t; } return s; } int main() { // Step 1. 入力 cin >> N; for (int i = 1; i <= N; i++) cin >> A[i] >> B[i]; // Step 2. 山登り法 for (int i = 1; i <= N - 1; i++) Order[i] = i + 2; long long CurrentScore = GetScore(); long long BestScore = CurrentScore; int StartTime = clock(); while (clock() - StartTime <= 85 * CLOCKS_PER_SEC / 100) { int idx1 = rand() % (N - 1) + 1; int idx2 = rand() % (N - 1) + 1; swap(Order[idx1], Order[idx2]); long long CandScore = GetScore(); double Diff = log10(CurrentScore) - log10(CandScore); if (Randouble() < exp(Diff / 0.2)) { if (BestScore > CandScore) { printf("%.2lf %.2lf\n", log10(BestScore), log10(CandScore)); BestScore = CandScore; for (int i = 1; i <= N; i++) BestOrder[i] = Order[i]; } CurrentScore = CandScore; } else { swap(Order[idx1], Order[idx2]); } } // Step 3. 答えを得る vector> Answer; for (int i = 1; i <= N - 1; i++) Answer.push_back(make_pair(1, BestOrder[i])); // Step 4. 出力 cout << Answer.size() << endl; for (int i = 0; i < Answer.size(); i++) cout << Answer[i].first << " " << Answer[i].second << endl; return 0; }