2020ICPC亚洲网上区域赛模拟赛D Pokemon Ultra Sun(概率DP+数学期望)

D Pokemon Ultra Sun

题目

Two pokemons are in a battle.One is our and another is the opposite’s.

Our pokemon is in confusion and the opposite’s pokemon is frozen.

Once per turn , the opposite’s pokemon does nothing and our pokemon gives w damages to the opposite’s pokemon with a probability of P while gives w damages to itself with a probability of 1 − P.

Our pokemon has hp1 health points and the opposite’s pokemon has hp2 health points.

If one pokemon’s health points are zero or below zero, the game is over.

Your task is to calculate the expected number of turn.

输入描述

The first line is an integer T(T ≤ 8) , the number of test cases.

For each test case, the first line contains three integers hp1, hp2, w(1 ≤ hp1, hp2, w ≤ 3000), representing our pokemon’s health points, the opposite’s health points and damage. The second line contains a real number P(0 < P < 1). which is described above.

输出描述

For each test case, print the expected number of turn rounding to 6 digits after decimal in one line.

题意

示例1

输入

1
1 1 1
0.5

输出

1.000000

题意

有两个口袋妖怪在战斗中,一个是我们的,另一个是相反的。

我们的宠物小精灵感到困惑,对方的宠物小精灵被冻结了。

每回合一次,对方的宠物小精灵什么都不做,我们的宠物小

精灵对对方的宠物小精灵造成w伤害,概率为P,而对自身的宠物小精灵造成w伤害,其概率为1-P。我们的宠物小精灵拥有hp1生命值,对方的宠物小精灵具有hp2健康要点。

如果一个宠物小精灵的健康点为零或低于零,则游戏结束。
输入描述:
第一行是整数T(T≤8),即测试用例的数量。

对于每个测试用例,第一行包含三个整数hp1,hp2,w(1≤hp1,hp2,w≤3000),分别代表我们的宠物小精灵的健康点,对面的健康点和伤害。第二行包含一个实数P(0 <P <1)。如上所述。
输出描述:
对于每个测试用例,将预期的转数四舍五入到一行中的小数点后6位。

C++实现

#include<iostream>
#include<cstring>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int hp1,hp2,w;//血量和攻击力
double p;//击中概率

double dp[3005][3005];//dp[i][j]表示我方掉i血,对方掉j血的期望 

int main()
{
	IO;
	int t;
	cin >> t;
	while(t--)
	{	
		memset(dp,0,sizeof (dp));
		cin >> hp1 >> hp2 >> w >> p;
		for(int i = 1; i <= hp1; i ++)
		{
			for(int j = 1; j <= hp2; j++)
			{
				dp[i][j] =  1.0 + p * dp[i][max(0,j - w)] + (1 - p) * dp[max(0,i - w)][j];
			}
		}
		printf("%.6lf\n",dp[hp1][hp2]);
	}
	
	return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值