NC213446. PokemonUltraSun(评测)
描述
输入描述
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;}