推错半天式子T T
设f[i]为买了i种卡,期望再买几张有n种卡
设g[i]为买了i种卡,期望再花多少钱有n种卡
可以把当前买卡的价格看作1,则以后买的所有卡片要增加1元,于是要加上f[i]和f[i+1]
#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]); }