推错半天式子T T

  设f[i]为买了i种卡,期望再买几张有n种卡

bzoj1426: 收集邮票(期望)

bzoj1426: 收集邮票(期望)

  设g[i]为买了i种卡,期望再花多少钱有n种卡

  可以把当前买卡的价格看作1,则以后买的所有卡片要增加1元,于是要加上f[i]和f[i+1]

bzoj1426: 收集邮票(期望)

bzoj1426: 收集邮票(期望)

#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm> 
using namespace std;
const int maxn=500010,inf=1e9;
int n;
double f[maxn],g[maxn];
inline void read(int &k)
{
    int f=1;k=0;char c=getchar();
    while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
    k*=f;
}
int main()
{
    read(n);
    for(int i=n-1;i>=0;i--)f[i]=f[i+1]+1.0*n/(n-i);
    for(int i=n-1;i>=0;i--)g[i]=1.0*i/(n-i)*f[i]+g[i+1]+f[i+1]+1.0*n/(n-i);
    printf("%.2lf",g[0]);
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-07-09
  • 2021-08-14
  • 2022-12-23
  • 2021-09-22
猜你喜欢
  • 2021-09-30
  • 2021-11-02
  • 2021-07-15
  • 2021-09-05
  • 2021-10-21
  • 2021-06-17
  • 2021-06-13
相关资源
相似解决方案