您的位置:首页 > 其它

BZOJ 4001[TJOI2015]概率论

2015-09-28 11:11 260 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: