fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <math.h>
  5.  
  6. int main() {
  7. int hours=1;
  8. while (hours < 25){
  9. int counter=0;
  10. int runs=100000;
  11. while ( runs > 0 ){
  12. //if( static_cast<int>((std::rand()/(static_cast<double>(RAND_MAX)+1.0)) * (hours)) > 0.25*hours ){
  13. int x = static_cast<int>((std::rand()/(static_cast<double>(RAND_MAX)+1.0)) * 100);
  14. if (x < (100*0.25 * log(hours)) ){
  15. counter++;
  16. }
  17. runs--;
  18. }
  19. std::cout << "hours: " << hours << " Interruptions: " << counter << "/100,000" << std::endl;
  20. hours++;
  21. }
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.29s 3412KB
stdin
Standard input is empty
stdout
hours: 1 Interruptions: 0/100,000
hours: 2 Interruptions: 17884/100,000
hours: 3 Interruptions: 27896/100,000
hours: 4 Interruptions: 34915/100,000
hours: 5 Interruptions: 40859/100,000
hours: 6 Interruptions: 45109/100,000
hours: 7 Interruptions: 48929/100,000
hours: 8 Interruptions: 52032/100,000
hours: 9 Interruptions: 55279/100,000
hours: 10 Interruptions: 57843/100,000
hours: 11 Interruptions: 59985/100,000
hours: 12 Interruptions: 63199/100,000
hours: 13 Interruptions: 65103/100,000
hours: 14 Interruptions: 65995/100,000
hours: 15 Interruptions: 67955/100,000
hours: 16 Interruptions: 69948/100,000
hours: 17 Interruptions: 70976/100,000
hours: 18 Interruptions: 73212/100,000
hours: 19 Interruptions: 73996/100,000
hours: 20 Interruptions: 74983/100,000
hours: 21 Interruptions: 76877/100,000
hours: 22 Interruptions: 77942/100,000
hours: 23 Interruptions: 79050/100,000
hours: 24 Interruptions: 79954/100,000