• 【poj2661】Factstone Benchmark(斯特林公式)


    传送门

    题意:
    给出(x,xleq 12),求最大的(n),满足(n!leq 2^{2^x})

    思路:
    通过斯特林公式:

    [n!approx sqrt{2pi n}cdot (frac{n}{e})^n ]

    我们一般可以认为这两个相等= =
    将阶乘转化为一个比较好求的式子,然后二分判断一下即可。

    /*
     * Author:  heyuhhh
     * Created Time:  2019/12/10 21:14:22
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #define MP make_pair
    #define fi first
    #define se second
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << '
    '; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    void pt() {std::cout << '
    '; }
    template<typename T, typename...Args>
    void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
    
    int n;
    
    bool chk(double x) {
        return 0.5 * log(2 * 3.1415926 * x) + x * log(x) - x <= pow(2, n) * log(2);
    }
    
    void run(){
        if(n == 0) return;
        n = (n - 1940) / 10 * 10 / 10;
        double l = 1, r = 1000000000000000, mid;
        for(int i = 0; i < 1000; i++) {
            mid = (l + r) / 2;
            if(chk(mid)) l = mid;
            else r = mid;   
        }
        cout << (ll)l << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        while(cin >> n) run();
        return 0;
    }
    
  • 相关阅读:
    = =写个prim希望能够巨巨们看的懂
    poj2389 普通的大数乘法
    Codeforces 378C
    hdoj1272 小希的迷宫
    hihoCoder搜索二·骑士问题
    hihoCoder扩展欧几里得
    hihoCoder 1032
    664A
    【水水水】678A
    Codeforces Round #357 (Div. 2)C. Heap Operations
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/12021248.html
Copyright © 2020-2023  润新知