hdu 4870 Rating

hdu 4870 Rating

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 414    Accepted Submission(s): 261
Special Judge




Problem Description
A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named “TopTopTopCoder”. Every user who has registered in “TopTopTopCoder” system will have a rating, and the initial value of rating equals to zero. After the user participates in the contest held by “TopTopTopCoder”, her/his rating will be updated depending on her/his rank. Supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his rating will be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach 1000 points as soon as possible, this little girl registered two accounts. She uses the account with less rating in each contest. The possibility of her rank between on 1 – 200 is P for every contest. Can you tell her how many contests she needs to participate in to make one of her account ratings reach 1000 points?

 


Input
There are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.
 


Output
You should output a float number for each test case, indicating the expected count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.
 


Sample Input
   
   
1.000000 0.814700

 


Sample Output
   
   
39.000000 82.181160

 


Author
FZU
 


Source
 

题目:一个女孩打比赛,每次比赛结果若在前200名则能给她的rating加上50分,否则将会将去100分(rating最小为0,最大为1000—-可以进入前200的概率为p)。为了可以达到1000分。这个女孩使用两个帐号进行比赛,每次使用rating低的那个帐号比赛,直到有一个帐号rating达到1000。给定一个p。问最后须要进行比赛场数的期望值。

题解:首先我们想到的是推公式,以dp[i]代表从i*50-(i+1)*50的期望值。dp[0]和dp[1]须要单独处理。

            dp[0]代表我们从0-50须要进行的场数,分成两种情况:1.成功,概率为p,期望为1*p

                                                                                                              2.失败。概率1-p。期望为(1-p)*(1+dp[0])  

                                                                                                                —–所以dp[0]=1*p+(1-p)*(1+dp[0]) ,化简后dp[0]=1/p;

            dp[1]代表我们从50-100的场数期望,分成两种情况:1.成功,概率为p,期望为1*p

                                                                                                           2.失败,概率1-p,期望为(1-p)*(1+dp[0]+dp[1])   

                                                                                                                —–所以dp[1]=1*p+(1-p)*(1+dp[0]+dp[1]) ,化简后dp[1]=1+(1-p)/p*(1+dp[0]);

            i>2,dp[i]的求法,分成两种情况:1.成功,概率为p。期望为1*p

                                                                       2.失败,概率1-p,期望为(1-p)*(1+dp[i-2]+dp[i-1]+dp[i])   

                                                                        —–所以dp[i]=1*p+(1-p)*(1+dp[i-2]+dp[i-1]+dp[i])   。化简后dp[i]=1+(1-p)/p*(1+dp[i-2]+dp[i-1]);

这样,由于要使用两个帐号进行比赛,所以我们最后到达的状态就是一个帐号rating=1000,另外一个=950,仅仅须要进行dp求和即可了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    double p,q;
    double dp[20];
    while(cin>>p)
    {
        memset(dp,0,sizeof(dp));
        q=1.0-p;

        double sum=0;
        dp[0]=1.0/p;
        dp[1]=1.0+q/p*(1+dp[0]);
        sum+=(dp[0]+dp[1])*2;

        for(int i=2;i<=19;i++)
        {
            dp[i]=1.0+q/p*(1+dp[i-1]+dp[i-2]);
            sum+=dp[i]*2;
        }
        printf("%.6lf\n",sum-dp[19]);
    }
    return 0;
}

 高斯消元的做法(公式同上):

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const double eps=1e-11;  //设置为1e-9时Wa了
double a[40][40],x[40];
int equ,var;

void Debug()
{
    for(int i=0; i<equ; i++)
    {
        for(int j=0; j<=var; j++)
            printf("%4.2lf ",a[i][j]);
        puts("");
    }
    puts("");
}

double Gauss()
{
    int k,col,max_r;

    for(k=0,col=0; k<equ&&col<var; k++,col++)
    {
        max_r=k;
        for(int i=k+1; i<equ; i++)
            if(fabs(a[i][col])>fabs(a[max_r][col])) max_r=i;

        if(max_r!=k)
            for(int i=0; i<=var; i++)
            {
                swap(a[max_r][i],a[k][i]);
            }

        if(fabs(a[k][col])<eps)
        {
            k--;
            continue;
        }

        for(int i=k+1; i<equ; i++)
        {
            if(fabs(a[i][col])>eps)
            {
                double t=a[i][col]/a[k][col];
                for(int j=col; j<=var; j++)
                {
                    a[i][j]=a[i][j]-a[k][j]*t;
                }
            }
        }
    }

    //Debug();

    double ans=0;
    for(int j=var-1; j>=0; j--)
    {
        double temp=a[j][var];
        for(int r=j+1; r<var; r++)
            temp=(temp-a[j][r]*x[r]);

        x[j]=temp/a[j][j];
    }
    for(int j=0; j<var; j++)
        ans+=2.0*x[j];
    return ans-x[19];
}

void init(double p)
{
    equ=var=20;
    memset(a,0,sizeof(a));
    memset(x,0,sizeof(x));
    for(int i=0; i<20; i++)
    {
        a[i][var]=1.0;
    }
    a[0][0]=p;
    a[1][0]=p-1;
    a[1][1]=p;
    for(int i=2; i<=19; i++)
    {
        a[i][i]=p;
        a[i][i-1]=p-1;
        a[i][i-2]=p-1;
    }
    //Debug();
}

int main()
{
    double p;
    while(scanf("%lf",&p)!=EOF)
    {
        init(p);
        printf("%.6lf\n",Gauss());
    }
    return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116993.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python神经网络图像识别note

    python神经网络图像识别noteBP神经网络手写数字识别mnist测试集(28*28)识别mnist训练集60000个样本,测试集10000个样本,发现使用4层BP神经网络784,50,20,10没有3层神经网络784,100,10识别率高.只有88%左右对自己手写的样本更差.先是处理了手写样本的背景色噪声,但是仍然很差,估计1.mnist训练集中对数字图像位置进行了居中,大小进行了统一,自己手写的样本没有做相应…

    2022年5月12日
  • curl命令大全(数据库命令大全)

    curl命令大全简介curl是常用的命令行工具,用来请求Web服务器。它的名字就是客户端(client)的URL工具的意思。它的功能非常强大,命令行参数多达几十种。如果熟练的话,完全可以取代Postman这一类的图形界面工具。[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7aHduX6w-1597403478458)(https://www.wangbase.com/blogimg/asset/201909/bg2019090501.jpg)]不带有任

    2022年4月16日
  • 图片加载出错后显示默认图片

    图片加载出错后显示默认图片图片加载出错后展示默认设置的图片img因网络问题以及其他问题加载出错时,展示成下图的样式网络出错时,没有设置默认图片显示成这样使用one()绑定事件是防止默认图片也加载不出,防止死循环$(“.listList2”).one(“error”,function(e){$(this).attr(“src”,”image/head_portrait.png”);});或者img元素自带onerror属性,加载失败时,触发error事件<imgsrc=”img/yuan.

    2022年7月26日
  • List集合转换成Json字符串

    List集合转换成Json字符串前言进行转换我们使用alibaba的jsonjar:com.alibaba.fastjson.jar1.导入依赖或者直接导入jar<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId&…

    2022年10月18日
  • 惠普打印机驱动安装出现严重错误_惠普 服务器

    惠普打印机驱动安装出现严重错误_惠普 服务器现在很多用户已经升级了win10正式版,但是也遇到了不少问题。默认情况下,Windows10系统会自动安装电脑设备的驱动,其中就包括打印机的。但是近日有些朋友反馈在更新HP打印机时,遇到错误提示“HPdriverupdateforHPLaserJetM1530MFPSeriesPCL6-错误0x80240017”,且会不停自动安装,而安装总是失败,这该怎么办呢?下面就详情…

    2022年8月12日
  • PLSQL Developer 12 注册码永久

    PLSQL Developer 12 注册码永久PLSQLDeveloper12注册码productcode:4vkjwhfeh3ufnqnmpr9brvcuyujrx3n3leserialNumber:226959password:xs374ca

    2022年7月24日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号