BZOJ 4001[TJOI2015]概率论

来源:互联网 发布:建筑工程优化设计方案 编辑:程序博客网 时间:2024/05/17 22:56

4001: [TJOI2015]概率论

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 583  Solved: 294
[Submit][Status][Discuss]

Description

Input

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

Output

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

Sample Input

1

Sample Output

1.000000000

HINT

 1<=N<=10^9

解题思路:

手动推了前5个,发现规律 ans = n * (n + 1) / 2 / (2 * n - 1);

#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <algorithm>#define LL long long using namespace std;const int MAXN = 1000 + 10;double N;int main(){    scanf("%lf", &N);    double ans = (N * (N + 1)) / 2.0 / (2.0 * N - 1.0);     printf("%.9lf\n", ans);    return 0;}


0 0