HDU4870:Rating(DP)
2015-12-09 20:38
302 查看
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
Sample Output
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 由于每次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#include <stdio.h> int main() { float p,sum,t[21],q; int i; while(~scanf("%f",&p)) { sum = 0; q = 1-p; t[0] = 1/p,t[1] = t[0]/p,t[2] = t[1]/p; sum = t[0]+t[1]+t[2]; for(i = 3;i<20;i++) { t[i] = (t[i-1]-t[i-3]*q)/p; sum+=t[i]; } printf("%.6f\n",sum*2-t[19]); } return 0; }
相关文章推荐
- TCP/IP-协议族----17、应用层简单
- 跟我extjs5(38--单个模块的设计[6获得模块列表数据])
- PL/SQL一个简短的引论
- 解决Eclipse自己主动补充问题空间
- Ubuntu14.04配置nginx开机自启动项
- 【Android】Fragment官方中文文档
- leetcode Word Search
- shell脚本中生成的spool文件没有执行的语句
- cocos2dx简介
- 属性树提供的操作函数
- Java对象循环引用,Java gc 如何回收
- 【android】移植IOS视图响应陀螺仪交互行为
- 【Life】 生命之花凋零之前,你绽放了吗?灿烂吗?
- 电桥-20151208
- sap JCO3.0安装时遇到的问题
- 四则运算-第二阶段-第一天
- JavaBean与JSON的转换
- python和php常用的时间处理
- 照片无缝滚动
- JFinalo操作框架racle数据库