2020-11-08

ICPC亚洲网上区域赛模拟赛D题补题

链接:https://ac.nowcoder.com/acm/contest/8688/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.

题意:

你有一只精灵,但是陷入了混乱状态(有一定概率(P)攻击自己),他和另一只精灵对战,双方各有h1和h2的生命值,你的精灵每一次攻击会造成W点伤害。问当有一只精灵生命值清零后造成伤害数值的数学期望。

做法:

比赛时先用深搜做了一遍,TLE了。之后就一直想着剪枝,但是一直wa。赛后发现是用概率DP来做。

#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
    int T;
    cin>>T;
    while(T--){
        double p;
        int h1,h2,w;
        double f[4000][4000];
        cin>>h1>>h2>>w>>p;
        for(int i=1;i<=h1;i++){
            for(int j=1;j<=h2;j++){
                f[i][j]=f[max(0,i-w)][j]*(1-p)+f[i][max(0,j-w)]*p+1.0;
            }
        }
        printf("%.6lf\n",f[h1][h2]);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值