1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int try_cnt = 100;
  13.  
  14. int stage;
  15. int cnt = 0;
  16. double[] s_prop = new double[] { 1, 0.9, 0.8, 0.7, 0.6 };
  17. double[] f_prop = new double[] { 0, 0.1, 0.2, 0.3, 0.4 };
  18.  
  19. for (int i = 0; i < try_cnt; i++) {
  20. stage = 0;
  21.  
  22. while (true) {
  23. if (stage == 5) {
  24. break;
  25. }
  26.  
  27. cnt++;
  28. if (Math.random() < s_prop[stage]) {
  29. stage++;
  30. } else {
  31. if (Math.random() < f_prop[stage]) {
  32. stage--;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. System.out.println("시행횟수 : " + try_cnt);
  39. System.out.println("5단계에 도달하는 평균 시행 횟수 : " + ((double) cnt / try_cnt));
  40. }
  41. }