fork(1) download
  1. #include <iostream>
  2. #include <random>
  3. #include <cstdint>
  4. #include <tuple>
  5. #include <algorithm>
  6.  
  7.  
  8. // 計算機以外の実行を禁ずる。
  9. std::size_t DoOne(std::size_t N, std::size_t C) {
  10. std::size_t V = 0;
  11. std::size_t Re = N;
  12. std::size_t T = 0;
  13.  
  14. std::random_device rd;
  15. std::mt19937 mt(rd());
  16. //std::mt19937 mt;
  17. std::uniform_int_distribution<std::size_t> UI(1, 10);
  18. do {
  19. N = Re;
  20. Re = 0;
  21. T = 0;
  22. for (std::size_t i = 0; i < N; i++) {
  23. std::size_t V = UI(mt);
  24. T = std::max(T,V);
  25.  
  26. if (V >= C) { Re++; }
  27.  
  28. }
  29. V += T;
  30. }while(Re != 0);
  31.  
  32. return V;
  33. }
  34.  
  35. int main() {
  36. std::uintmax_t V = 0;
  37.  
  38. std::size_t DiceCount = 10;
  39. std::size_t NumberLimit = 5;
  40. std::size_t L = 1200000;
  41. std::size_t Min = 11*DiceCount;
  42. std::size_t Max = 0;
  43. for (std::size_t i = 0; i < L; i++) {
  44. std::size_t T = DoOne(DiceCount, NumberLimit);
  45. V += T;
  46. Min = std::min(Min, T);
  47. Max = std::max(Max, T);
  48.  
  49. }
  50.  
  51. std::cout << "Do " << L << " count." << std::endl;
  52. std::cout << "Min:" << Min << ',' << "Max:" << Max << std::endl;
  53. std::cout << "Average:" << V / (double)L << std::endl;
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 5s 4268KB
stdin
Standard input is empty
stdout
Do 1200000 count.
Min:3,Max:234
Average:47.0382