Water blog pleasing (fog)
The following title single from https://www.cnblogs.com/Morning-Glory/p/11228082.html orzorzorz
SP1026 FAVDICE - Favorite Dice
N a die face, enables seeking desired throw times are thrown into each side.
Relatively routine questions
I throw now set to face one surface of the new roll a probability (ni) / n.
No side throw new probability i / n.
Therefore, the formula is f [i] = i / nf [i] + (ni) / nf [i + 1] +1 (to roll a)
Simplification is f [i] = f [i + 1] + n / (ni)
Note that the case of n == 1, 1 / c ++ 0 in case the value is not yet clear.
As direct the f [0] is set to 1 output.
In fact, the formula is very easy to push, but not too long push very unskilled)
View Code1 #include<bits/stdc++.h> 2 #define re register int 3 #define db double 4 #define maxn 1000+5 5 using namespace std; 6 db f[maxn]; 7 int t,n; 8 int main() 9 { 10 cin>>t; 11 while(t--) 12 { 13 cin>>n; 14 if(n==1) f[0]=1; 15 else{ 16 f[n]=0; 17 for(re i=n-1;i>=0;i--) 18 f[i]=f[i+1]+(db)n/(db)(n-i); 19 } 20 printf("%.2lf",f[0]); 21 cout<<endl; 22 } 23 return 0; 24 }