fork(2) download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int i, j, n, d;
  9. cin >> n >> d;
  10. double prob = 1. / d;
  11. vector<double> a(n);
  12. a[0] = 1.;
  13. for (i = 0; i < n; i++)
  14. if (a[i] > .0) {
  15. double next = a[i] * prob;
  16. for (j = 1; j <= d && i + j < n; j++)
  17. a[i + j] += next;
  18. }
  19. cout << setprecision(9) << fixed;
  20. for (i = 0; i < n; i++)
  21. cout << i + 1 << ": " << a[i] << '\n';
  22. }
  23.  
Success #stdin #stdout 0s 3432KB
stdin
32 6
stdout
1: 1.000000000
2: 0.166666667
3: 0.194444444
4: 0.226851852
5: 0.264660494
6: 0.308770576
7: 0.360232339
8: 0.253604395
9: 0.268094017
10: 0.280368945
11: 0.289288461
12: 0.293393122
13: 0.290830213
14: 0.279263192
15: 0.283539659
16: 0.286113932
17: 0.287071430
18: 0.286701925
19: 0.285586725
20: 0.284712810
21: 0.285621080
22: 0.285967984
23: 0.285943659
24: 0.285755697
25: 0.285597993
26: 0.285599871
27: 0.285747714
28: 0.285768820
29: 0.285735625
30: 0.285700953
31: 0.285691829
32: 0.285707469