bzoj4001 [TJOI2015]概率论

Description

Input

输入一个正整数N,代表有根树的结点数

Output

 输出这棵树期望的叶子节点数。要求误差小于1e-9

Sample Input

1

Sample Output

1.000000000

HINT

 1<=N<=10^9

正解:期望。

首先可以打表找规律得到代码里的式子。

然后证明的话,不是很会,可以看看这篇博客:Miskcoo's Space

 1 #include <bits/stdc++.h>
 2 #define il inline
 3 #define RG register
 4 #define ll long long
 5 
 6 using namespace std;
 7 
 8 int main(){
 9 #ifndef ONLINE_JUDGE
10   freopen("probability.in","r",stdin);
11   freopen("probability.out","w",stdout);
12 #endif
13   int n; cin>>n;
14   printf("%0.12lf
",0.5*n*(n+1)/(2*n-1));
15   return 0;
16 }
原文地址:https://www.cnblogs.com/wfj2048/p/8030084.html