HDU 4870 Rating (2014 多校联合第一场 J)(概率)

题意:

一个人有两个TC的账号,一开始两个账号rating都是0,然后每次它会选择里面rating较小的一个账号去打比赛,每次比赛有p的概率+1分,有1-p的概率-2分,当然如果本身是<=2分的也就还是回到0分。然后问最后其中一个账号到达20分时需要打多少次比赛。

思路:

因为每次50分,到达1000分,所以可以看做每次1分,到达20分
dp[i]表示i到20的数学期望
那么dp[i] = dp[i+1]*p+dp[i-2]*q+1;
令t[i] = dp[i+1]-dp[i]
则t[i] = (t[i+1]*p+t[i-2]*q)
所以t[i+1] = (t[i]-t[i-2]*q)/p

代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 //t[i]为从i分到i+1分需要的比赛次数期望
 5 int main()
 6 {
 7     double t[21],dp[21];
 8     double p,q,sum;
 9     while(scanf("%lf",&p)!=EOF)
10     {
11         sum = 0;
12         q = 1-p;
13         t[0] = 1/p;
14         t[1] = t[0]/p;
15         t[2] = t[1]/p;
16         sum =t[0]+t[1]+t[2];
17         for(int i=3;i<20;i++)
18         {
19             t[i]=(t[i-1]-t[i-3]*q)/p;
20             sum+=t[i];
21         }
22         //sum为一个账号达到20分的平均比赛次数
23         printf("%.6lf\n",2*sum-t[19]);//按照比赛规则,一个账号到20分的比赛次数=两个账号到20分的次数减去一个账号从19分到二十分的比赛次数
24     }
25     return 0;
26 }
时间: 2024-10-12 16:01:12

HDU 4870 Rating (2014 多校联合第一场 J)(概率)的相关文章

hdu 4865 Peter&amp;#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2.给定n天的叶子湿度状态,求这n天最可能的天气情况 分析:概率dp设 dp[i][j] 表示第i天天气为j的最大概率,pre[i][j]表示第i天天气最可能为j的前一天天气,dp[i][j]=max(dp[i-1][k]+log(wePro[k][j])+log(lePro[j][lePos[i]]

hdu 4869 Turn the pokers (2014多校联合第一场 I)

Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1265    Accepted Submission(s): 465 Problem Description During summer vacation,Alice stay at home for a long time, with nothing t

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

2014多校联合第一场

1001:Couple doubi 暴力打表找规律可知,对于任意的p. (1^i+2^i+...+(p-1)^i)%p={ 非0     ,i%(p-1)==0 0        ,  i%(p-1)!=0 } 所以,结果就很显然了. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<c

HDU 4869 Turn the pokers (2014 多校联合第一场 I)

HDOJ--4869--Turn the pokers[组合数学+快速幂] 题意:有m张扑克,开始时全部正面朝下,你可以翻n次牌,每次可以翻xi张,翻拍规则就是正面朝下变背面朝下,反之亦然,问经过n次翻牌后牌的朝向有多少种情况.我们可以把正面朝上理解为1,反面朝上理解为0,那么可以理解为求01串的不同的组合方式有几种. 解题思路:我们可以知道,每张牌假设起始状态都为0,如果翻奇数次,该牌最后的情况是1,如果翻偶数次,该牌的最后情况为0.根据n次翻牌的个数找出1的个数的下限和上限,然后再在这个范围

HDU 5289 Assignment(多校联合第一场1002)

Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 617    Accepted Submission(s): 314 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fr

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to