fork download
  1. #include <assert.h>
  2. #include <stdio.h>
  3.  
  4. #define START (0)
  5. #define RED_END (START + 19)
  6. #define GREEN_END (RED_END + 22)
  7. #define BLACK_END (GREEN_END + 28)
  8. #define WHITE_END (BLACK_END + 19)
  9. #define YELLOW_END (WHITE_END + 14)
  10. #define ORANGE_END (YELLOW_END + 8)
  11. #define END (ORANGE_END)
  12.  
  13. #define RED_BIT (1 << 0)
  14. #define GREEN_BIT (1 << 1)
  15. #define BLACK_BIT (1 << 2)
  16. #define WHITE_BIT (1 << 3)
  17. #define YELLOW_BIT (1 << 4)
  18. #define ORANGE_BIT (1 << 5)
  19.  
  20. #define PICK_NUM (4)
  21.  
  22. int allDiffColor(int ball[])
  23. {
  24. char hitCheck = 0;
  25. int i;
  26.  
  27. for (i = 0; i < PICK_NUM; ++i)
  28. {
  29. if (ball[i] < RED_END)
  30. {
  31. if (hitCheck & RED_BIT)
  32. {
  33. return 0;
  34. }
  35. else
  36. {
  37. hitCheck |= RED_BIT;
  38. }
  39. }
  40. else if (ball[i] < GREEN_END)
  41. {
  42. if (hitCheck & GREEN_BIT)
  43. {
  44. return 0;
  45. }
  46. else
  47. {
  48. hitCheck |= GREEN_BIT;
  49. }
  50. }
  51. else if (ball[i] < BLACK_END)
  52. {
  53. if (hitCheck & BLACK_BIT)
  54. {
  55. return 0;
  56. }
  57. else
  58. {
  59. hitCheck |= BLACK_BIT;
  60. }
  61. }
  62. else if (ball[i] < WHITE_END)
  63. {
  64. if (hitCheck & WHITE_BIT)
  65. {
  66. return 0;
  67. }
  68. else
  69. {
  70. hitCheck |= WHITE_BIT;
  71. }
  72. }
  73. else if (ball[i] < YELLOW_END)
  74. {
  75. if (hitCheck & YELLOW_BIT)
  76. {
  77. return 0;
  78. }
  79. else
  80. {
  81. hitCheck |= YELLOW_BIT;
  82. }
  83. }
  84. else if (ball[i] < ORANGE_END)
  85. {
  86. if (hitCheck & ORANGE_BIT)
  87. {
  88. return 0;
  89. }
  90. else
  91. {
  92. hitCheck |= ORANGE_BIT;
  93. }
  94. }
  95. else
  96. {
  97. assert(0);
  98. }
  99. }
  100.  
  101. return 1;
  102. }
  103.  
  104. int main()
  105. {
  106. int ball[PICK_NUM] = {0};
  107. int allCount = 0;
  108. int hitCount = 0;
  109.  
  110. for (ball[0] = 0; ball[0] < END; ball[0]++)
  111. {
  112. for (ball[1] = 0; ball[1] < END; ball[1]++)
  113. {
  114. if (ball[0] == ball[1])
  115. continue;
  116. for (ball[2] = 0; ball[2] < END; ball[2]++)
  117. {
  118. if ((ball[0] == ball[2]) || (ball[1] == ball[2]))
  119. continue;
  120. for (ball[3] = 0; ball[3] < END; ball[3]++)
  121. {
  122. if ((ball[0] == ball[3]) || (ball[1] == ball[3]) || (ball[2] == ball[3]))
  123. continue;
  124. ++allCount;
  125.  
  126. if (1 == allDiffColor(ball))
  127. {
  128. ++hitCount;
  129. }
  130. }
  131. }
  132. }
  133. }
  134.  
  135. printf("all: %d, hit: %d\n", allCount, hitCount);
  136. }
Success #stdin #stdout 1.26s 9424KB
stdin
Standard input is empty
stdout
all: 138556440, hit: 34960224