fork(1) download
  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. static Random rand = new Random(123456L);
  11.  
  12. static void shuffle(int[] list)
  13. {
  14. for (int i = 0; i < list.length; ++i)
  15. {
  16. int a = i;
  17. int b = rand.nextInt(list.length);
  18.  
  19. // Swap
  20. int t = list[a];
  21. list[a] = list[b];
  22. list[b] = t;
  23. }
  24. }
  25.  
  26.  
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. // your code goes here
  30.  
  31. // Init
  32. int[] list = new int[1000];
  33.  
  34. init(list);
  35. shuffle(list);
  36. show(list);
  37. System.out.println("[new 1000]shuffle");
  38. analyze(list);
  39.  
  40. shuffle(list);
  41. System.out.println("shuffle one more");
  42. analyze(list);
  43.  
  44. init(list);
  45. shuffle(list);
  46. System.out.println("[new 1000]shuffle");
  47. analyze(list);
  48.  
  49. init(list);
  50. shuffle(list);
  51. System.out.println("[new 1000]shuffle");
  52. analyze(list);
  53.  
  54. for (int i = 0; i < 10; ++i)
  55. {
  56. shuffle(list);
  57. }
  58. System.out.println("shuffle 10 times");
  59. analyze(list);
  60.  
  61. list = new int[3000];
  62. init(list);
  63. shuffle(list);
  64. System.out.println("[new 3000]shuffle");
  65. analyze(list);
  66.  
  67. for (int i = 0; i < 10; ++i)
  68. {
  69. shuffle(list);
  70. }
  71. System.out.println("shuffle 10 times");
  72. analyze(list);
  73.  
  74. for (int j = 0; j < 3; ++j)
  75. {
  76. list = new int[100];
  77. init(list);
  78. shuffle(list);
  79. System.out.println("[new 100]shuffle");
  80. analyze(list);
  81.  
  82. for (int i = 0; i < 10; ++i)
  83. {
  84. shuffle(list);
  85. }
  86. System.out.println("shuffle 10 times");
  87. analyze(list);
  88. }
  89. }
  90.  
  91. static int makeValue(int n)
  92. {
  93. return n / 10;
  94. }
  95.  
  96. static void init(int[] list)
  97. {
  98. for (int i = 0; i < list.length; ++i)
  99. {
  100. list[i] = makeValue(i);
  101. }
  102. }
  103.  
  104. static void show(int[] list)
  105. {
  106. for (int n : list)
  107. {
  108. System.out.print(n + " ");
  109. }
  110. System.out.println();
  111. }
  112.  
  113. static void analyze(int[] list)
  114. {
  115. System.out.println("** analyze **");
  116. int sum = 0;
  117. for (int i = 1; i < list.length; ++i)
  118. {
  119. sum += Math.abs(list[i] - list[i - 1]);
  120. }
  121. double avg = (double)sum / (double)(list.length - 1);
  122. double s2 = 0.0;
  123. for (int i = 1; i < list.length; ++i)
  124. {
  125. double diff = (double)Math.abs(list[i] - list[i - 1]);
  126. s2 += (avg - diff) * (avg - diff);
  127. }
  128. s2 /= (double)(list.length - 1);
  129. System.out.println("diff avg: " + avg);
  130. System.out.println("diff s2: " + s2);
  131.  
  132. int count = 0;
  133. for (int i = 0; i < list.length; ++i)
  134. {
  135. int v = makeValue(i);
  136. if (v == list[i])
  137. {
  138. ++count;
  139. }
  140. }
  141. System.out.println("stay: " + count);
  142.  
  143. int suc = 0;
  144. for (int i = 1; i < list.length; ++i)
  145. {
  146. if (list[i] == list[i - 1])
  147. {
  148. ++suc;
  149. }
  150. }
  151. System.out.println("succeession: " + suc);
  152. }
  153. }
Success #stdin #stdout 0.1s 380544KB
stdin
Standard input is empty
stdout
52 53 66 56 48 95 0 26 91 80 13 10 40 99 39 70 23 55 38 2 18 38 45 71 82 9 96 0 29 46 97 3 65 40 26 81 23 21 73 25 52 37 26 76 39 14 10 47 8 23 43 30 83 2 12 17 1 24 62 50 33 35 35 61 8 5 90 95 20 18 60 49 10 1 87 59 37 13 61 50 65 88 85 42 32 70 77 25 59 67 56 46 99 2 42 95 83 50 12 91 91 83 52 76 29 60 8 1 75 10 16 49 40 34 35 15 74 11 7 99 93 28 97 68 26 21 89 40 57 27 56 1 70 49 65 9 62 52 58 85 27 50 62 26 34 24 92 7 13 54 87 53 25 73 95 33 72 78 17 51 29 27 94 87 98 74 34 34 9 24 25 31 13 62 0 78 11 14 45 77 9 66 33 44 66 43 0 93 79 6 12 19 11 24 81 40 48 72 81 53 34 34 94 39 54 23 45 48 81 16 71 97 15 20 25 25 29 42 34 2 48 81 1 6 28 51 17 22 72 78 28 22 21 80 60 38 42 39 90 64 46 6 43 66 59 49 56 53 23 12 12 3 85 44 88 88 7 35 63 41 4 79 57 86 63 28 9 64 10 11 79 69 40 97 50 58 68 24 92 78 33 98 97 70 65 23 27 40 42 46 63 3 32 30 5 69 64 46 69 78 20 73 50 73 33 1 64 19 2 19 5 18 37 21 32 1 49 84 27 60 37 95 67 12 1 60 21 50 62 39 53 20 70 66 81 59 77 85 92 93 8 26 38 51 41 58 32 24 93 73 92 67 30 13 45 58 77 22 97 5 25 32 42 4 88 54 75 36 86 79 18 81 85 13 62 47 54 82 22 45 4 48 37 98 47 51 52 7 81 90 36 48 8 0 55 82 17 36 77 60 86 54 30 44 96 55 24 35 85 84 92 26 35 14 68 64 98 78 41 74 15 72 11 60 42 87 38 44 68 71 39 4 4 71 94 46 17 28 95 18 56 56 36 18 94 92 53 91 78 32 3 55 64 35 30 47 3 20 68 12 40 4 42 14 16 21 44 35 87 80 8 30 91 72 61 4 31 56 43 10 39 94 57 84 72 0 14 74 37 32 89 33 15 38 13 76 25 38 67 92 43 56 16 21 7 16 32 33 41 90 7 14 73 16 89 22 94 6 80 91 40 46 65 37 63 27 11 32 34 16 13 38 78 51 23 63 70 7 86 55 83 19 89 48 84 63 31 90 6 55 79 19 64 68 79 3 12 69 5 76 64 51 60 74 96 20 71 53 30 49 83 58 96 54 32 14 21 43 84 58 68 83 84 60 27 18 84 56 31 83 91 53 74 96 41 5 92 79 13 10 66 86 35 22 2 61 65 82 43 65 55 50 55 43 45 89 2 39 74 82 75 52 76 74 82 66 12 67 15 52 59 12 97 88 98 67 79 65 2 99 73 3 11 24 54 3 72 74 96 46 50 63 2 31 7 10 18 35 11 8 34 31 67 80 34 47 57 64 20 71 11 38 9 10 95 19 0 5 67 67 22 80 20 2 94 44 37 66 68 57 5 75 27 90 29 7 57 57 90 77 4 65 51 57 93 71 69 13 36 44 83 59 31 77 53 29 85 38 48 87 52 27 79 3 76 23 78 28 85 21 63 63 83 1 49 25 15 99 75 94 58 77 49 76 17 69 65 14 22 4 70 66 36 86 70 50 58 75 96 86 83 89 33 93 15 47 24 45 41 86 15 7 18 1 20 33 82 96 6 23 10 17 8 98 37 39 60 22 61 54 70 93 89 90 90 15 91 55 94 54 84 95 48 63 29 19 73 43 54 87 25 49 61 93 4 81 62 95 61 29 69 41 49 9 29 53 69 93 70 9 16 98 97 99 89 61 41 82 23 36 29 87 3 40 26 14 47 64 46 75 17 30 45 20 43 16 62 17 86 28 58 73 99 42 88 88 75 31 71 47 51 61 51 91 88 87 18 91 33 97 69 45 36 96 57 88 92 84 80 82 76 8 68 55 6 11 99 92 19 0 66 81 58 89 76 82 28 39 76 26 6 85 27 24 72 80 42 69 96 30 71 94 87 5 99 71 84 19 51 22 98 62 80 47 6 8 97 46 93 86 59 9 52 26 21 80 78 0 56 57 37 52 0 41 75 45 72 74 68 73 98 62 95 85 90 36 28 98 59 88 31 44 47 48 16 77 14 36 15 6 61 17 5 9 44 19 31 41 77 28 67 89 59 75 44 59 30 72 99 79 
[new 1000]shuffle
** analyze **
diff avg: 31.93893893893894
diff s2: 544.7500253005763
stay: 18
succeession: 14
shuffle one more
** analyze **
diff avg: 33.32132132132132
diff s2: 546.4402961520072
stay: 16
succeession: 14
[new 1000]shuffle
** analyze **
diff avg: 33.25525525525526
diff s2: 535.9418517616717
stay: 7
succeession: 5
[new 1000]shuffle
** analyze **
diff avg: 32.389389389389386
diff s2: 533.1967242517798
stay: 16
succeession: 12
shuffle 10 times
** analyze **
diff avg: 34.25625625625626
diff s2: 557.8222206190169
stay: 11
succeession: 6
[new 3000]shuffle
** analyze **
diff avg: 98.87862620873625
diff s2: 4860.820213384455
stay: 12
succeession: 8
shuffle 10 times
** analyze **
diff avg: 98.59753251083694
diff s2: 4917.85035736598
stay: 8
succeession: 11
[new 100]shuffle
** analyze **
diff avg: 3.3838383838383836
diff s2: 5.8324660748903145
stay: 12
succeession: 4
shuffle 10 times
** analyze **
diff avg: 3.6565656565656566
diff s2: 5.8416488113457765
stay: 10
succeession: 5
[new 100]shuffle
** analyze **
diff avg: 3.393939393939394
diff s2: 5.753902662993572
stay: 9
succeession: 12
shuffle 10 times
** analyze **
diff avg: 3.414141414141414
diff s2: 5.5557596163656795
stay: 10
succeession: 11
[new 100]shuffle
** analyze **
diff avg: 3.212121212121212
diff s2: 5.318640955004589
stay: 7
succeession: 11
shuffle 10 times
** analyze **
diff avg: 3.5555555555555554
diff s2: 5.519640852974186
stay: 13
succeession: 10