Solução do Problema Candy Lottery do CSES
Resolução problema Candy Lottery do CSES.
Solução do Problema Candy Lottery do CSES
Problem
There are \(n\) children, and each of them independently gets a random integer number of candies between 1 and \(k\). What is the expected maximum number of candies a child gets?
Input
The only input line contains two integers \(n\) and \(k\).
Output
Print the expected number rounded to six decimal places (rounding half to even).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
int k;
cin >> n >> k;
ld ans = 0;
for (int i = 1; i <= k; i++)
{
ld prob_max_menor_que_i = pow((ld)(i - 1) / k, n);
ans += (1.0 - prob_max_menor_que_i);
}
cout << fixed << setprecision(6) << ans;
return 0;
}
This post is licensed under CC BY 4.0 by the author.