列表

详情


NC213446. PokemonUltraSun(评测)

描述

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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 71ms, 内存消耗: 70980K, 提交时间: 2020-11-01 22:48:26

#include<bits/stdc++.h>
using namespace std;
#define f(i,b) for(int i=1;i<=b;++i)
double d[3005][3005],P;int main(){int t,H,h,w;cin>>t;
while(t--){cin>>H>>h>>w>>P;int a=(H+w-1)/w,b=(h+w-1)/w;
f(i,a)f(j,b)d[i][j]=d[i-1][j]*(1-P)+d[i][j-1]*P+1;
printf("%.6lf\n",d[a][b]);
}return 0;}

上一题