zoukankan      html  css  js  c++  java
  • Day11

    设dp_i为所求答案,每次选择因数的概率相同,设i有x个因数,dp_i=sum(1/x*x_j)+1,(x_j表示第j个因数),那我们就预处理每个数的因数即可,T=10000,需要预处理出答案

    #include<bits/stdc++.h>
    using namespace std;
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    typedef pair<int,int> pii;
    
    const int maxn = 1e5+5;
    vector<int> factor[maxn];
    double dp[maxn];
    
    void get_factor() {
        for(int i = 1; i < maxn; ++i) {
            for(int j = i; j < maxn; j += i)
                factor[j].push_back(i);
        }
    }
    
    void prework() {
        for(int i = 2; i < maxn; ++i) {
            int siz = factor[i].size();
            for(int j = 0; j < siz-1; ++j) {
                dp[i] += 1.0/siz * dp[factor[i][j]];
            }
            dp[i]++;
            dp[i] *= (double)siz/(siz-1);
        }
    }
    
    void run_case() {
        int n; cin >> n;
        cout << dp[n] << "
    ";
    }
     
    int main() {
        //ios::sync_with_stdio(false), cin.tie(0);
        cout.flags(ios::fixed);cout.precision(10);
        int t; cin >> t;
        //while(t--)
        get_factor();
        prework();
        for(int i = 1; i <= t; ++i) {
            cout << "Case " << i << ": ";
            run_case();
        }
        //cout.flush();
        return 0;
    }
    View Code
  • 相关阅读:
    Less34-Less37 (宽字节注入)
    宽字节注入 Less32-Less33
    Less29(jspstudy)-Less31
    Less26-Less28a
    Less23-Less25a(24--二次注入)
    Less 11-22
    sqli-labs 1-10
    sqli-labs环境搭建与安装
    OSPF与ACL综合实例
    用分治法完成比赛操作
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12342030.html
Copyright © 2011-2022 走看看