1.4.2 Mother's Milk

  
    
  1. /*
  2. ID: awsd1231
  3. PROG: milk3
  4. LANG: C++
  5. */
  6. #include<iostream>
  7. #include<cstdio>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. int A, B, C, idx = 0;
  12. int may[25][25][25] = {0};
  13. struct T {
  14. int a, b, c;
  15. }can[10000];
  16. queue<T> ans;
  17. set<int> ansN;
  18. int main() {
  19. freopen("milk3.in", "r", stdin);
  20. freopen("milk3.out", "w", stdout);
  21. cin >> A >> B >> C;
  22. can[idx].a = 0;
  23. can[idx].b = 0;
  24. can[idx].c = C;
  25. ans.push(can[idx]);
  26. may[0][0][C] = 1;
  27. int x[3];
  28. while(!ans.empty()) {//6种情况,如果没出现过就入队
  29. if(ans.front().a > B - ans.front().b) { //a->b
  30. x[0] = ans.front().a - B + ans.front().b;
  31. x[1] = B;
  32. x[2] = ans.front().c;
  33. if(may[x[0]][x[1]][x[2]] == 0) {
  34. may[x[0]][x[1]][x[2]] = 1;
  35. can[++idx].a = x[0];
  36. can[idx].b = x[1];
  37. can[idx].c = x[2];
  38. ans.push(can[idx]);
  39. }
  40. } else {
  41. x[0] = 0;
  42. x[1] = ans.front().b + ans.front().a;
  43. x[2] = ans.front().c;
  44. if(may[x[0]][x[1]][x[2]] == 0) {
  45. may[x[0]][x[1]][x[2]] = 1;
  46. can[++idx].a = x[0];
  47. can[idx].b = x[1];
  48. can[idx].c = x[2];
  49. ans.push(can[idx]);
  50. }
  51. }
  52. ///////////////////////
  53. if(ans.front().a > C - ans.front().c) { //a->c
  54. x[0] = ans.front().a - C + ans.front().c;
  55. x[1] = ans.front().b;
  56. x[2] = C;
  57. if(may[x[0]][x[1]][x[2]] == 0) {
  58. may[x[0]][x[1]][x[2]] = 1;
  59. can[++idx].a = x[0];
  60. can[idx].b = x[1];
  61. can[idx].c = x[2];
  62. ans.push(can[idx]);
  63. }
  64. } else {
  65. x[0] = 0;
  66. x[1] = ans.front().b;
  67. x[2] = ans.front().a + ans.front().c;
  68. if(may[x[0]][x[1]][x[2]] == 0) {
  69. may[x[0]][x[1]][x[2]] = 1;
  70. can[++idx].a = x[0];
  71. can[idx].b = x[1];
  72. can[idx].c = x[2];
  73. ans.push(can[idx]);
  74. }
  75. }
  76. ///////////////////////
  77. if(ans.front().b > A - ans.front().a) { //b->a;
  78. x[0] = A;
  79. x[1] = ans.front().b - A + ans.front().a;
  80. x[2] = ans.front().c;
  81. if(may[x[0]][x[1]][x[2]] == 0) {
  82. may[x[0]][x[1]][x[2]] = 1;
  83. can[++idx].a = x[0];
  84. can[idx].b = x[1];
  85. can[idx].c = x[2];
  86. ans.push(can[idx]);
  87. }
  88. } else {
  89. x[0] = ans.front().a + ans.front().b;
  90. x[1] = 0;
  91. x[2] = ans.front().c;
  92. if(may[x[0]][x[1]][x[2]] == 0) {
  93. may[x[0]][x[1]][x[2]] = 1;
  94. can[++idx].a = x[0];
  95. can[idx].b = x[1];
  96. can[idx].c = x[2];
  97. ans.push(can[idx]);
  98. }
  99. }
  100. ///////////////////////
  101. if(ans.front().b > C - ans.front().c) { //b->c
  102. x[0] = ans.front().a;
  103. x[1] = ans.front().b - C + ans.front().c;
  104. x[2] = C;
  105. if(may[x[0]][x[1]][x[2]] == 0) {
  106. may[x[0]][x[1]][x[2]] = 1;
  107. can[++idx].a = x[0];
  108. can[idx].b = x[1];
  109. can[idx].c = x[2];
  110. ans.push(can[idx]);
  111. }
  112. } else {
  113. x[0] = ans.front().a;
  114. x[1] = 0;
  115. x[2] = ans.front().b + ans.front().c;
  116. if(may[x[0]][x[1]][x[2]] == 0) {
  117. may[x[0]][x[1]][x[2]] = 1;
  118. can[++idx].a = x[0];
  119. can[idx].b = x[1];
  120. can[idx].c = x[2];
  121. ans.push(can[idx]);
  122. }
  123. }
  124. ///////////////////////
  125. if(ans.front().c > A - ans.front().a) { //c->a
  126. x[0] = A;
  127. x[1] = ans.front().b;
  128. x[2] = ans.front().c - A + ans.front().a;
  129. if(may[x[0]][x[1]][x[2]] == 0) {
  130. may[x[0]][x[1]][x[2]] = 1;
  131. can[++idx].a = x[0];
  132. can[idx].b = x[1];
  133. can[idx].c = x[2];
  134. ans.push(can[idx]);
  135. }
  136. } else {
  137. x[0] = ans.front().a + ans.front().c;
  138. x[1] = ans.front().b;
  139. x[2] = 0;
  140. if(may[x[0]][x[1]][x[2]] == 0) {
  141. may[x[0]][x[1]][x[2]] = 1;
  142. can[++idx].a = x[0];
  143. can[idx].b = x[1];
  144. can[idx].c = x[2];
  145. ans.push(can[idx]);
  146. }
  147. }
  148. ///////////////////////
  149. if(ans.front().c > B - ans.front().b) { //c->b
  150. x[0] = ans.front().a;
  151. x[1] = B;
  152. x[2] = ans.front().c - B +ans.front().b;
  153. if(may[x[0]][x[1]][x[2]] == 0) {
  154. may[x[0]][x[1]][x[2]] = 1;
  155. can[++idx].a = x[0];
  156. can[idx].b = x[1];
  157. can[idx].c = x[2];
  158. ans.push(can[idx]);
  159. }
  160. } else {
  161. x[0] = ans.front().a;
  162. x[1] = ans.front().b + ans.front().c;
  163. x[2] = 0;
  164. if(may[x[0]][x[1]][x[2]] == 0) {
  165. may[x[0]][x[1]][x[2]] = 1;
  166. can[++idx].a = x[0];
  167. can[idx].b = x[1];
  168. can[idx].c = x[2];
  169. ans.push(can[idx]);
  170. }
  171. }
  172. ///////////////////////
  173. ans.pop();
  174. }
  175. for(int i = 0; i != 25; ++i) {
  176. for(int j = 0; j != 25; ++j) {
  177. if(may[0][i][j]) ansN.insert(j);
  178. }
  179. }
  180. for(set<int>::iterator it = ansN.begin(); it != --ansN.end(); ++it) {
  181. cout << *it << " ";
  182. }
  183. cout << *(--ansN.end()) << endl;
  184. return 0;
  185. }





你可能感兴趣的:(r)