fork download
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. int scores[6][3];
  5.  
  6. int trials[6][3];
  7.  
  8. int questions[4][6][3] =
  9. {
  10. {
  11. { 5, 0, 0 },
  12. { 3, 0, 2 },
  13. { 2, 0, 3 },
  14. { 0, 0, 5 },
  15. { 4, 0, 1 },
  16. { 1, 0, 4 },
  17. },
  18. {
  19. { 4, 1, 0 },
  20. { 3, 0, 2 },
  21. { 4, 1, 0 },
  22. { 1, 1, 3 },
  23. { 0, 0, 5 },
  24. { 1, 1, 3 },
  25. },
  26. {
  27. { 5, 0, 0 },
  28. { 4, 0, 1 },
  29. { 2, 2, 1 },
  30. { 2, 0, 3 },
  31. { 1, 0, 4 },
  32. { 0, 0, 5 },
  33. },
  34. {
  35. { 5, 0, 0 },
  36. { 3, 1, 1 },
  37. { 2, 1, 2 },
  38. { 2, 0, 3 },
  39. { 0, 0, 5 },
  40. { 1, 0, 4 },
  41. },
  42. };
  43.  
  44. #include <iostream>
  45. using namespace std;
  46.  
  47. constexpr int matches[][2] =
  48. {
  49. { 0, 1 }, { 0, 2 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
  50. { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 },
  51. { 2, 3 }, { 2, 4 }, { 2, 5 },
  52. { 3, 4 }, { 3, 5 },
  53. { 4, 5 },
  54. };
  55.  
  56. enum RESULT
  57. {
  58. win,
  59. even,
  60. lose,
  61. };
  62.  
  63. bool possible;
  64.  
  65. void test( int game_index );
  66.  
  67. inline void test_sub(
  68. const int team_a, const RESULT result_a,
  69. const int team_b, const RESULT result_b,
  70. const int game_index )
  71. {
  72. if( trials[ team_a ][ result_a ] + 1 <= scores[ team_a ][ result_a ] &&
  73. trials[ team_b ][ result_b ] + 1 <= scores[ team_b ][ result_b ] )
  74. {
  75. trials[ team_a ][ result_a ]++;
  76. trials[ team_b ][ result_b ]++;
  77. test( game_index + 1 );
  78. trials[ team_a ][ result_a ]--;
  79. trials[ team_b ][ result_b ]--;
  80. }
  81. }
  82.  
  83. void test( int game_index )
  84. {
  85. if( game_index >= sizeof matches / sizeof *matches )
  86. {
  87. possible = true;
  88. return;
  89. }
  90.  
  91. const int team_a = matches[ game_index ][ 0 ];
  92. const int team_b = matches[ game_index ][ 1 ];
  93.  
  94. test_sub( team_a, win, team_b, lose, game_index );
  95. if( possible ) return;
  96.  
  97. test_sub( team_a, lose, team_b, win, game_index );
  98. if( possible ) return;
  99.  
  100. test_sub( team_a, even, team_b, even, game_index );
  101. if( possible ) return;
  102. }
  103.  
  104. int main()
  105. {
  106. for( int i = 0; i < 4; ++i )
  107. {
  108. memset( trials, 0, sizeof trials );
  109. memcpy( scores, questions + i, sizeof scores );
  110. possible = false;
  111. test( 0 );
  112. cout << possible << " ";
  113. }
  114. cout << endl;
  115. return 0;
  116. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
1 1 0 0