期望DP——(HDU6658)The Moon

3 篇文章 0 订阅

题目

he Moon card shows a large, full moon in the night’s sky, positioned between two large towers. The Moon is a symbol of intuition, dreams, and the unconscious. The light of the moon is dim, compared to the sun, and only vaguely illuminates the path to higher consciousness which winds between the two towers.

Random Six is a FPS game made by VBI(Various Bug Institution). There is a gift named “Beta Pack”. Mr. K wants to get a beta pack. Here is the rule.
Step 0. Let initial chance rate qq = 2%.
Step 1. Player plays a round of the game with winning rate pp.
Step 2. If the player wins, then will go to Step 3 else go to Step 4.
Step 3. Player gets a beta pack with probability qq. If he doesn’t get it, let qq = min(100%, qq + 2%) and he will go to Step 1.
Step 4. Let qq = min(100%, qq + 1.5%) and goto Step 1.
Mr. K has winning rate pp% , he wants to know what’s the expected number of rounds before he needs to play.

Input
The first line contains testcase number TT (TT ≤ 100). For each testcase the first line contains an integer pp (1 ≤ pp ≤ 100).

Output
For each testcase print Case ii : and then print the answer in one line, with absolute or relative error not exceeding 1e6.

Sample Input
2
50
100

Sample Output
Case 1: 12.9933758002
Case 2: 8.5431270393

题意

假设玩一个游戏,每局都有P%的概率能赢(P已知),初始中奖率为Q=2%;赢的时候可以抽奖,如果中奖了就结束游戏,如果没中奖Q+2%;输的时候不抽奖,Q+1.5%。
在这里插入图片描述

解析

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

正确代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
    double a[205];
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        memset(a,0,sizeof(a));
        double p;
        scanf("%lf",&p);
        p/=100;
        a[200]=1/p;
        for(int q=199;q>=1;q--) a[q]=p*(a[min(q+4,200)]*(1-q/200.0)+1)+(1-p)*(a[min(q+3,200)]+1);
        printf("Case %d: %.10f\n",i,a[4]);
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值