2014 多校联赛第一场 1010Rating

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
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

 

题意:有一个人参加某个比赛,初始得分是0,她有两个账号,每次用当前分数低的账号打比赛,如果赢了,加上50分(最多1000分),输了减去100分(最低减到0),她每次打赢比赛的概率为p,问他得到1000分的期望比赛场数是几场。

 

思路:先分析一下她是如何达到1000分的,首先,她先用一个号升到50分,然后换另一个号升到50分,再任取一个号升到100分。。。当一个号分数比另一个低时,她会一直使用这个号,知道分数超过另一个号,所以可以 用f[i]表示她单用一个号从i*50分升高到(i+1)*50分的概率。

于是f[i] = p*1(她这场比赛直接赢了,) + (1-p)*(1+f[i-2] + f[i-1])(她这场比赛输了,于是降100分,再从(i-2)*50分升到(i-1)*50分再升到i*50分,最后再升到(i+1)*50分)

 

然后就好办了,她的两个号每升高50分需要的比赛场次是2*f[i](i*50是她当前的分数),最后还要减掉一个从950分升高到1000分所需的比赛场数(因为只要一个号到了1000分就成功了)

下面是代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include <queue>

using namespace std;

const int MAXN = 21;
const int INF = 2100000000;

double f[MAXN];
double p;
int main()
{
        //freopen("C:/Users/Admin/Desktop/in.txt", "r", stdin);
        while(cin >> p)
        {
                f[0] = 0;
                f[1] = 1/p;
                for(int i = 2; i <= 20; i++)
                {
                        f[i] = 1/p + (1-p)/p * (f[i-2] + f[i-1]);
                }

                double ans = 0;
                for(int i = 0; i <= 20; i++)
                {
                        if(i != 20)
                        ans += 2*f[i];
                        else
                        ans += f[i];
                }

                printf("%.6lf\n", ans);
        }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值