【HDU - 6558】The Moon(期望dp)
题干:
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 106106.
Sample Input
2 50 100
Sample Output
Case 1: 12.9933758002 Case 2: 8.5431270393
题目大意:
为了得到一件奖品而玩一个游戏(游戏有好多局),得到奖品后游戏结束。游戏中的每一局都有p%的概率会赢(p是个给定的常数),初始中奖率q=2,如果这一局赢了就抽奖,没抽到就q+2,然后继续游戏的下一局;如果这一局输了就q+1.5。问玩的游戏局数的期望。中奖率最高为100%,也就是说如果这一局赢了且没抽到奖,那q=min(q+2,100%) 如果这一局输了,那q=min(q+1.5,100%)。
解题报告:
设dp[i]代表当前状态的中奖率为 i% 时,得到奖品的期望天数。
因为已知状态是终点的状态,所以倒着dp。考虑初始化,dp[100]=1/p。(当然,注意p上来要先除以100,因为他给的是p%)
又因为此时中奖的概率是100%,也就是说赢即可以中奖,也就是转化成赢的期望局数,赢一局的概率是p,显然这符合几何概型,所以期望局数=1/p。
然后转移就是 dp[i]= p * [ q*1+(1-q)*(dp[i+2]+1)] + (1-p) * (dp[i+1.5] + 1)
分别代表: 赢游戏的前提下 ( 中奖 没中奖 ) 没赢游戏
然后化简一下公式就可以了。注意这里因为有0.5不能放到状态中,所以直接都*2,这样状态变成0~200.这样就方便转移了。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
double dp[255],p;
int main()
{int T,iCase=0;cin>>T;while(T--) {scanf("%lf",&p); p/=100;double gp = 1.0/p;dp[200] = gp;for(int i = 199; i>=1; i--) {dp[i] = p*((1-i/200.0)*dp[min(i+4,200)]+1) + (1-p)*(dp[min(i+3,200)]+1);}printf("Case %d: %.10f\n",++iCase,dp[4]);}return 0 ;
}
【HDU - 6558】The Moon(期望dp)相关推荐
- HDU 6656 Kejin Player (期望DP 逆元)
2019 杭电多校 7 1011 题目链接:HDU 6656 比赛链接:2019 Multi-University Training Contest 7 Problem Description Cub ...
- HDU 4652 Dice:期望dp(成环)【错位相减】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意: 给你一个有m个面的骰子. 两种询问: (1)"0 m n": &qu ...
- HDU 4405 Aeroplane chess(期望DP)
题目链接 理解了过程就是个水题,收拾东西回家. 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring ...
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- Everything Is Generated In Equal Probability HDU 6595(期望dp)
大致题意 好像是给一个数字n,然后随机选择一个1到n的数字,对其排列进行这样一种运算.首先res加上当前排列的逆序对数,然后再随机选择当前数列的子序列,继续进行该运算直到子序列长度为0.求res的期望 ...
- luogu P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现) Weblin ...
- [SCOI2008]奖励关(期望dp)
你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再吃). 宝 ...
- 【bzoj4318】OSU! 期望dp
题目描述 osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的0 ...
- 【loj6342】跳一跳 期望dp
题目描述 一个人从 $1$ 开始向 $n$ 跳,在 $i$ 时会等概率跳到 $i,i+1,...,n$ 之一.求从 $1$ 跳到 $n$ 的期望步数. $n\le 10^7$ . 题解 期望dp傻逼题 ...
- 【高斯消元】兼 【期望dp】例题
[总览] 高斯消元基本思想是将方程式的系数和常数化为矩阵,通过将矩阵通过行变换成为阶梯状(三角形),然后从小往上逐一求解. 如:$3X_1 + 2X_2 + 1X_3 = 3$ $ ...
最新文章
- hexo d 部署博客时出错
- centos7下没有iptables
- linux学习笔记4:linux的任务调度,进程管理,mysql的安装和使用,ssh工具的使用,linux网络编程...
- jQuery学习笔记:Ajax(二)
- css - clearfix-清除浮动
- shiro利用mysql动态授权_SpringBoot+Shiro学习之数据库动态权限管理和Redis缓存
- CodeSmith 创建Ado.Net自定义模版(一)
- 机械工程人工智能_机械工程中的人工智能
- 完整的元器件选型指南
- python编码无法使用turtle库_使用Turtle库教Python
- 阿里云ECS后台CPU占用100%,top却找不到
- 微信公众号开发之消息的自动回复
- HarmonyOS(鸿蒙)——单击事件
- gerrit常见错误与处理
- 网络营销成功案例分析篇:NIKE网络营销案例
- 3w最简单led灯电路图_怎么选择自己合适的LED驱动IC?(十大LED驱动IC典型应用电路图)...
- Flutter系列之设置Dialog的宽度
- Surface pro系统重装
- STM32+光敏模块
- 【音视频流媒体】WebRTC 直播超详细介绍
热门文章
- 实时修改和读取webconfig
- 数据结构五——二叉树
- POJ-1384 Piggy-Bank 多重背包变形
- Elegant Construction HDU-5813 构造
- word java api,是否有可以创建丰富Word文档的Java API?
- md5与des算法有何不同_到底AI芯片和传统芯片有何区别?
- 计算机excel知识点一级,2012年计算机一级考试高分必看知识点:EXCEL
- 上传本地项目到gitee_用git上传本地文件到码云gitee的方法
- python安装copy_python中copy和deepcopy 的区别
- java+session+存在哪_JAVA中Session