fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int result[4][4];
  5. int score[4];
  6. int fav;
  7. int wins=0;
  8. void print_result()
  9. {
  10. for (int i=0; i<4; i++)
  11. {
  12. for (int j=0; j<4; j++)
  13. {
  14. cout << result[i][j] <<" ";
  15. }
  16. cout << endl;
  17. }
  18.  
  19. }
  20.  
  21. pair <int,int> next_match()
  22. {
  23. for (int i=0; i<3; i++)
  24. {
  25. for (int j=i+1; j<4; j++)
  26. {
  27. if (result[i][j] == -1) return make_pair<int,int>(i,j);
  28. }
  29. }
  30. return make_pair<int,int>(-1,-1);
  31. }
  32. bool win()
  33. {
  34. for (int i; i< 4; i++)
  35. {
  36. if (i!= fav && score[fav]<= score[i] ) return false;
  37. }
  38. return true;
  39. }
  40. void add_score(int a, int b, int match_result)
  41. {
  42. if (match_result == 0)
  43. {
  44. score[a] += 3;
  45. }
  46. if (match_result == 1)
  47. {
  48. score[a] += 1;
  49. score[b] += 1;
  50. }
  51. if (match_result == 2)
  52. {
  53. score[b] += 3;
  54. }
  55. }
  56. void sub_score(int a, int b, int match_result)
  57. {
  58. if (match_result == 0)
  59. {
  60. score[a] -= 3;
  61. }
  62. else if (match_result == 1)
  63. {
  64. score[a] -= 1;
  65. score[b] -= 1;
  66. }
  67. else if (match_result == 2)
  68. {
  69. score[b] -= 3;
  70. }
  71. }
  72. void eval_next_match()
  73. {
  74. pair <int,int> match;
  75. match=next_match();
  76. cout << "New " <<match.first << " matching " << match.second << endl;
  77. //cout << " 1: "<< score[0]<< " 2: "<< score[1]<< " 3: "<< score[2]<< " 4: "<< score[3]<<endl;
  78. if (match.first == -1 && match.second==-1)
  79. {
  80. cout << "Number of WINS " <<wins<< endl;
  81. if (win()) wins++;
  82. return;
  83. }
  84. for (int i = 0; i < 3; i++)
  85. {
  86. result[match.first][match.second]=i;
  87. add_score(match.first,match.second, result[match.first][match.second]);
  88. print_result();
  89. cout << "IF "<< result[match.first][match.second] << endl;
  90. cout << " 1: "<< score[0]<< "\n 2: "<< score[1]<< "\n 3: "<< score[2]<< "\n 4: "<< score[3]<<endl;
  91. eval_next_match();
  92. sub_score(match.first,match.second, result[match.first][match.second]);
  93. result[match.first][match.second]=-1;
  94. }
  95. return;
  96. }
  97. int main()
  98. {
  99. int m, temp;
  100.  
  101. int a,b,c,d;
  102. for (int i = 0; i < 4; i++)
  103. {
  104. score[i]=0;
  105. for (int j=0; j< 4 ; j++)
  106. {
  107. result[i][j]=-1;
  108. }
  109. }
  110.  
  111. cin >> fav>> m;
  112. cout << fav <<" "<< m << endl;
  113. cout << " 1: "<< score[0]<< "\n 2: "<< score[1]<< "\n 3: "<< score[2]<< "\n 4: "<< score[3]<<endl;
  114.  
  115. for (int i = 0; i < m; i++)
  116. {
  117. cin >> a >> b >> c >>d;
  118. cout << a<< " "<< b <<" "<< c <<" " << d<< endl;
  119. if (a > b)
  120. {
  121. temp =a;
  122. a=b;
  123. b=a;
  124. temp=c;
  125. c=d;
  126. d=c;
  127. }
  128. if (c > d)
  129. {
  130. result[a-1][b-1]=0;
  131. }
  132. else if (c == d)
  133. {
  134. result[a-1][b-1]=1;
  135. }
  136. else if (c < d)
  137. {
  138. result[a-1][b-1]=2;
  139. }
  140. add_score(a-1,b-1, result[a-1][b-1]);
  141. cout << "Played " <<a << " matching " << b << endl;
  142.  
  143. cout << " result "<< result[a-1][b-1] << endl;
  144. cout << " 1: "<< score[0]<< "\n 2: "<< score[1]<< "\n 3: "<< score[2]<< "\n 4: "<< score[3]<<endl;
  145.  
  146. }
  147. print_result();
  148. eval_next_match();
  149. cout << wins << endl;
  150.  
  151. return 0;
  152. }
Success #stdin #stdout 0s 3348KB
stdin
3
3
1 3 7 5
3 4 0 8
2 4 2 2
stdout
3  3
   1:  0
   2:  0
   3:  0
   4:  0
1 3 7 5
Played     1   matching  3
  result   0
   1:  3
   2:  0
   3:  0
   4:  0
3 4 0 8
Played     3   matching  4
  result   2
   1:  3
   2:  0
   3:  0
   4:  3
2 4 2 2
Played     2   matching  4
  result   1
   1:  3
   2:  1
   3:  0
   4:  4
-1 -1 0 -1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
New 0   matching  1
-1 0 0 -1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  6
   2:  1
   3:  0
   4:  4
New 0   matching  3
-1 0 0 0 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  9
   2:  1
   3:  0
   4:  4
New 1   matching  2
-1 0 0 0 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  9
   2:  4
   3:  0
   4:  4
New -1   matching  -1
Number of WINS 0
-1 0 0 0 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  9
   2:  2
   3:  1
   4:  4
New -1   matching  -1
Number of WINS 0
-1 0 0 0 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  9
   2:  1
   3:  3
   4:  4
New -1   matching  -1
Number of WINS 0
-1 0 0 1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  7
   2:  1
   3:  0
   4:  5
New 1   matching  2
-1 0 0 1 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  7
   2:  4
   3:  0
   4:  5
New -1   matching  -1
Number of WINS 0
-1 0 0 1 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  7
   2:  2
   3:  1
   4:  5
New -1   matching  -1
Number of WINS 0
-1 0 0 1 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  7
   2:  1
   3:  3
   4:  5
New -1   matching  -1
Number of WINS 0
-1 0 0 2 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  6
   2:  1
   3:  0
   4:  7
New 1   matching  2
-1 0 0 2 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  6
   2:  4
   3:  0
   4:  7
New -1   matching  -1
Number of WINS 0
-1 0 0 2 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  6
   2:  2
   3:  1
   4:  7
New -1   matching  -1
Number of WINS 1
-1 0 0 2 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  6
   2:  1
   3:  3
   4:  7
New -1   matching  -1
Number of WINS 2
-1 1 0 -1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  4
   2:  2
   3:  0
   4:  4
New 0   matching  3
-1 1 0 0 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  7
   2:  2
   3:  0
   4:  4
New 1   matching  2
-1 1 0 0 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  7
   2:  5
   3:  0
   4:  4
New -1   matching  -1
Number of WINS 3
-1 1 0 0 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  7
   2:  3
   3:  1
   4:  4
New -1   matching  -1
Number of WINS 3
-1 1 0 0 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  7
   2:  2
   3:  3
   4:  4
New -1   matching  -1
Number of WINS 3
-1 1 0 1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  5
   2:  2
   3:  0
   4:  5
New 1   matching  2
-1 1 0 1 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  5
   2:  5
   3:  0
   4:  5
New -1   matching  -1
Number of WINS 3
-1 1 0 1 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  5
   2:  3
   3:  1
   4:  5
New -1   matching  -1
Number of WINS 3
-1 1 0 1 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  5
   2:  2
   3:  3
   4:  5
New -1   matching  -1
Number of WINS 3
-1 1 0 2 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  4
   2:  2
   3:  0
   4:  7
New 1   matching  2
-1 1 0 2 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  4
   2:  5
   3:  0
   4:  7
New -1   matching  -1
Number of WINS 3
-1 1 0 2 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  4
   2:  3
   3:  1
   4:  7
New -1   matching  -1
Number of WINS 4
-1 1 0 2 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  4
   2:  2
   3:  3
   4:  7
New -1   matching  -1
Number of WINS 5
-1 2 0 -1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  3
   2:  4
   3:  0
   4:  4
New 0   matching  3
-1 2 0 0 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  6
   2:  4
   3:  0
   4:  4
New 1   matching  2
-1 2 0 0 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  6
   2:  7
   3:  0
   4:  4
New -1   matching  -1
Number of WINS 6
-1 2 0 0 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  6
   2:  5
   3:  1
   4:  4
New -1   matching  -1
Number of WINS 6
-1 2 0 0 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  6
   2:  4
   3:  3
   4:  4
New -1   matching  -1
Number of WINS 6
-1 2 0 1 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  4
   2:  4
   3:  0
   4:  5
New 1   matching  2
-1 2 0 1 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  4
   2:  7
   3:  0
   4:  5
New -1   matching  -1
Number of WINS 6
-1 2 0 1 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  4
   2:  5
   3:  1
   4:  5
New -1   matching  -1
Number of WINS 6
-1 2 0 1 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  4
   2:  4
   3:  3
   4:  5
New -1   matching  -1
Number of WINS 6
-1 2 0 2 
-1 -1 -1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  3
   2:  4
   3:  0
   4:  7
New 1   matching  2
-1 2 0 2 
-1 -1 0 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 0
   1:  3
   2:  7
   3:  0
   4:  7
New -1   matching  -1
Number of WINS 7
-1 2 0 2 
-1 -1 1 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 1
   1:  3
   2:  5
   3:  1
   4:  7
New -1   matching  -1
Number of WINS 7
-1 2 0 2 
-1 -1 2 1 
-1 -1 -1 2 
-1 -1 -1 -1 
IF 2
   1:  3
   2:  4
   3:  3
   4:  7
New -1   matching  -1
Number of WINS 8
9