fork download
  1. import java.util.Random;
  2. import java.lang.Math;
  3. public class Main{
  4. public static void main(String[] args){
  5. int x=0;
  6. double result=0;
  7. for(int i=0;i<100000;i++) {
  8. x = change(x);
  9. result =result+( x / 4);
  10. }
  11. System.out.print(result/100000);
  12. }
  13. public static int change(int x){
  14. int[] sum = new int[52];
  15. int[] data = {1,2,3,4,5,6,7,8,9,10,11,12,13,
  16. 1,2,3,4,5,6,7,8,9,10,11,12,13,
  17. 1,2,3,4,5,6,7,8,9,10,11,12,13,
  18. 1,2,3,4,5,6,7,8,9,10,11,12,13};//撲克牌
  19.  
  20. Random r = new Random();
  21. int[] array = new int[52];
  22. for (int i=0; i<52; i++){
  23. array[i] = r.nextInt(52);
  24. for (int j=0; j<i;){
  25. if (array[j]==array[i]){
  26. array[i] = r.nextInt(52);
  27. j=0;
  28. }
  29. else j++;
  30. }
  31. }
  32.  
  33. for(int i=0;i<52;i++){
  34. sum[i]=data[array[i]];
  35. }//將撲克牌的順序打亂
  36. int count=0;//蓋牌次數
  37. int t = 0;//牌的位置
  38. for(int m=0;m<4;m++) {
  39. for (int i = 10; i > 0; i--) {
  40. if (sum[t + 10 - i] == i) {
  41. t = t + 10 - i + 1;
  42. break;
  43. } else if (sum[t+9] != 1 && i == 1) {
  44. count++;
  45. t = t + 11;//蓋牌
  46. }
  47. }
  48. }
  49. x=count;
  50. return x;
  51. }
  52. }
Success #stdin #stdout 0.59s 119924KB
stdin
Standard input is empty
stdout
0.03949