zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 101 (Rated for Div. 2)D. Ceil Divisions(思维)

    D. Ceil Divisions

    题意

    给你n个数,每次可以这样操作((x otequiv y,a_x = lceil{a_y/a_x} ceil)),问你最多操作n+5次使最后变为一个2和n-1个1

    思路

    首先考虑时间复杂度(3 leq sum n leq 2*10^5)我们发现必须在(O(nlogn))以为来解决这个问题,然后通过找规律我们发现要使其在n+5次操作内完成,那我们必须有一个急速降幂过程,然后我们以极限数据(2e5)为例来推,发现(2e5->sqrt(2e5)->21.147->4.598->2.144->1.464)共进行了5次的操作,那么我们猜测这个问题的解决方法就是通过开根号上取整作为分界点来处理数据的。

    #include<bits/stdc++.h>
    using namespace std;
    const int N = 2e5 + 100;
    typedef long long LL;
    //#define int long long 
    
    void solve() {
    	int n; cin >> n;
    	vector<pair<int,int>>ans;
    	int t = n;
    	while (1) {
    		if (t <= 2) break;
    		int x = sqrt(t);
    		if (x * x < t) ++x;
    		for (int i = x + 1; i < t; ++i)ans.push_back({i, t});
    		ans.push_back({t, x});
    		ans.push_back({t, x});
    		t = x;
    	}
    	cout << ans.size() << endl;
    	for (auto it : ans) {
    		 cout << it.first << " " << it.second << endl;
    	}
    }
    signed main() {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    
    	int T = 1;
    	cin >> T;
    	while (T--) {
    		solve();
    	}
    
    }
    
  • 相关阅读:
    重写不受限制
    类的向上转型(安全)向下转型(不安全)
    类的继承之构造函数和析构函数的顺序
    父类和子类的截断现象
    派生类重写方法
    运算符重载总结(大全)
    运算符重载方法3
    运算符重载方法2
    Shell基础编程
    TCP Wrappers(简单防火墙)---限制IP登录ssh
  • 原文地址:https://www.cnblogs.com/waryan/p/14295264.html
Copyright © 2011-2022 走看看