1. 程式人生 > 其它 >Educational Codeforces Round 101 (Rated for Div. 2) D. Ceil Divisions

Educational Codeforces Round 101 (Rated for Div. 2) D. Ceil Divisions

https://codeforces.ml/contest/1469/problem/D

顯然,容易構造n+20步完成.而在多出5步的情況下考慮每次保留sqrt(n)
按照下面進行構造:
\([1,2,3,4,5,6,7,8,9] to [1,2,3,1,1,1,1,1,9] to [1,2,3,1,1,1,1,1,3] to [1,2,3,1,1,1,1,1,1]...\)

tips: +20 考慮按二進位制, +5 考慮按根號分塊

const int maxn = 2e5 + 7;
 
#define int long long
int n, t, m;
 
vector<pair<int, int>> vec;
vector<vector<pair<int, int>>> ans;
int a[maxn];
 
void solve() {
    cin >> t;
    while (t--) {
        cin >> n;
        vec.clear();
        ans.clear();
        int now = n;
        for (int i = n - 1; i >= 2; i--) {
            if (i * i > now) {
                vec.push_back({i, i + 1});
            } else {
                reverse(all(vec));
                ans.push_back(vec);
                vec.clear();
                ans.push_back({{n, i}});
                now = (now + i - 1) / i;
                vec.push_back({i, n});
            }
        }
        for (int i = 1; i <= n; i++)
            a[i] = i;
        vector<pair<int, int>> vec;
        for (auto v:ans)
            for (auto i :v)
                vec.push_back(i);
        vec.push_back({n, 2});
        vec.push_back({n, 2});
        vec.push_back({3, 2});
        vec.push_back({3, 2});
        cout << vec.size() << endl;
        for (auto i :vec) {
//            a[i.first] = (a[i.first] + a[i.second] - 1) / a[i.second];
            cout << i.first << " " << i.second << endl;
        }
//        for (int i = 1; i <= n; i++)
//            cout << a[i] << " ";
    }
}
我看見 你