#include#include#include#include#include#include#" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

UVa 11762 - Race to 1

系統(tǒng) 2206 0

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2862

暈 多加了一個(gè)# wa了N久? 細(xì)節(jié)呀

代碼及其注釋:

      #include<iostream>

#include<cstdio>

#include<string>

#include<cstring>

#include<cmath>

#include<set>

#include<map>

#include<stack>

#include<vector>

#include<algorithm>

#include<queue>



#define ull unsigned long long

#define ll long long

#define lint long long

using namespace std;



const double eps=1e-12;

const int INF=0x3f3f3f3f;

const int N=1000010;

double dp[N];//記憶化搜索數(shù)組

int p[N];//標(biāo)記是否是素?cái)?shù)

int prime[N];//將素?cái)?shù)從小到大放到prime數(shù)組里面

double dfs(int x)

{

    if(dp[x]>=-0.5)

    return dp[x];//記憶化

    if(x==1)//邊界

    return (dp[x]=0.0);

    double sum=0.0;

    int p=0,g=0;//p表示所有小于等于x的素?cái)?shù)個(gè)數(shù) g表示這些素?cái)?shù)中是x的約數(shù)的個(gè)數(shù)

    for(p=0;prime[p]<=x;++p)//枚舉所以小于等于x的素?cái)?shù)

    if(x%prime[p]==0)

    {

        ++g;

        sum+=dfs(x/prime[p]);

    }

    return (dp[x]=(sum+p)/g);//這個(gè)式子推導(dǎo)可得

}

int main()

{

    //freopen("data.in","r",stdin);

    memset(p,-1,sizeof(p));

    int ln=0;

    for(int i=2;i<N;++i)

    {

        if(p[i])

        {

            prime[ln++]=i;

            for(int j=i+i;j<N;j+=i)

            {

                p[j]=0;

            }

        }

    }

    for(int i=0;i<N;++i) dp[i]=-1.0;

    int T;

    scanf("%d",&T);

    for(int c=1;c<=T;++c)

    {

        int n;

        scanf("%d",&n);

        printf("Case %d: %.10lf\n",c,dfs(n));

    }

    return 0;

}


    

?

UVa 11762 - Race to 1


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 米林县| 广丰县| 柳林县| 拜城县| 南安市| 合水县| 静安区| 仪陇县| 防城港市| 乐至县| 云安县| 大悟县| 舞阳县| 牙克石市| 巨鹿县| 华蓥市| 珲春市| 江安县| 廊坊市| 内江市| 克什克腾旗| 温宿县| 昭苏县| 南靖县| 文登市| 平利县| 遵化市| 石渠县| 双峰县| 莫力| 沁源县| 沾化县| 京山县| 遂溪县| 雅安市| 江陵县| 响水县| 松江区| 丘北县| 阳朔县| 彭水|