好久不更了。。菜鸡还是要打ACM。。来博客拔一拔草(水题求不喷
大意就是给一个初始获得奖励的概率
P
做任务可以使概率增加
于是每做完一个任务就有一个概率
X
如果
如果这次拿到了奖励那么概率变为
⌊P2l⌋%
,其中
l
是当前已经获得的奖励个数
现在要求获得
N≤106,P≤100,Q≤100
那么期望的计算式可以写成
Ei=Σpk∗lk
,其中
pk
表示做了
lk
个任务后拿到i个奖励的概率
用
Pi
表示
⌊P2i⌋%
接着考虑
Ei+1=Σp′k∗l′k
=Pi+1∗Σpk∗(lk+1)
+(1−Pi+1)∗(Pi+1+Q%)∗Σpk∗(lk+2)
+(1−Pi+1)∗(1−Pi+1−Q%)∗(Pi+1+2Q%)∗Σpk∗(lk+3)+...
直到
Pi+1+kQ%
超过
1
结束
于是用
Ei+1=Σp′k∗l′k
=Pi+1∗(Ei+ci)
+(1−Pi+1)∗(Pi+1+Q%)∗(Ei+2ci)
+(1−Pi+1)∗(1−Pi+1−Q%)∗(Pi+1+2Q%)∗(Ei+3ci)+...
每次计算的次数不会超过
100
,复杂度上界为
O(100N)
注意当 i≥8 的时候 Pi为0,如果在i很大的时候直接计算Pi会出问题
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ull unsigned long long
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define scln(x) scanf("%d\n", &x)
#define sc64ln(x) scanf("%I64d\n", &x)
#define pr(x) printf("%d", x)
#define prln(x) printf("%d\n", x)
#define prsp(x) printf("%d ", x)
#define pr64(x) printf("%I64d", x)
#define pr64ln(x) printf("%I64d\n", x)
#define pr64sp(x) printf("%I64d ", x)
#define rep(i,n) for (int i = 1;i <= (n); ++i)
#define repr(i,n) for (int i = (n);i > 0; --i)
#define repab(i,a,b) for (int i = a;i <= b; ++i)
#define Rep(i,n) for (int i = 0;i < (n); ++i)
#define Repr(i,n) for (int i = (n)-1;i >= 0; --i)
#define Repab(i,a,b) for (int i = a;i < b; ++i)
#define SET(__set, val) memset(__set, val, sizeof __set)
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
template<class T> T power(T a, T b){T res(1);while(b){if(b&1)res=res*a;a=a*a;b>>=1;}return res;}
template<class T> T powerM(T a, T b, T mod){T res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
const int infi = 2147483647;
const ll infl = 9223372036854775807;
#define N 1111000
#define M 1000
int n, m, k;
double f[N], c[N];
int main()
{
double p, q, p1, p2;
sc(m), sc(k), sc(n);
p1 = p = m, q = k;
p2 = 1.0;
p1 /= 100;
f[1] = 0.0;
rep(i,100){
f[1] += (p1*p2)*i;
c[1] += p1*p2;
if (p1 == 1)break;
p2 *= 1-p1;
p1 += q/100;
if (p1 > 1)p1 = 1;
}
repab(i,2,n){
if (i >= 8)
p1 = 0;
else
p1 = floor(p/(1<<(i-1)))/100.0;
p2 = 1.0;
f[i] = 0.0;
rep(j,100){
f[i-1] += c[i-1];
f[i] += p1*p2*f[i-1];
c[i] += p1*p2;
if (p1 == 1)break;
p2 *= 1-p1;
p1 += q/100;
if (p1 > 1)p1 = 1;
}
}
printf("%.2lf\n", f[n]);
return 0;
}