jzoj 6824. 【2020.10.17提高组模拟】英雄联盟(lol)
Description
Input
共一行,包含一个正整数 x。含义详见题面。
Output
输出一行一个实数,表示答案。
Solution
设ans为期望多少刀暴击一刀,则\(\frac{1}{ans}\)就是答案
设exp[i]表示期望i刀暴击1刀
则\(ans=\sum_{i=1}^{\frac{100}{x}}exp[i]\)
exp[i]应该很好求
exp[i]的期望应该是i\(\times\)(第i刀暴击的概率)\(\times\)(第1~i-1刀不暴击的概率)
还不懂的可以看代码
#include <cstdio>
#include <algorithm>
#define open(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int x,pl;
long double t,pro,ans;
int main()
{
open("lol");
scanf("%d",&x);
pl=1;
t=1;
pro=x/100.0;
while (pro<1)
{
ans+=pl*t*pro;
t*=(1-pro);
pro+=x/100.0;
pl++;
}
ans+=pl*t;
printf("%.10Lf",1/ans);
return 0;
}
如果自己说什麽都做不到而什麽都不去做的话,那就更是什麽都做不到,什麽都不会改变,什麽都不会结束.