-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChances of Winning.cpp
106 lines (93 loc) · 2.27 KB
/
Chances of Winning.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <map>
using namespace std;
map<pair<int, int>, int> games = {};
int favorite;
int n_games;
int scores[4];
int t1, t2, s1, s2;
int sum;
int c;
void chances();
void win(pair<int, int> game){
// append the counter
n_games ++;
// win the game
games[game] = 1;
scores[(game.first - 1)] += 3;
// move onto next game
chances();
// reverse actions done (so other rounds can begin)
games[game] = 0;
scores[game.first - 1] -= 3;
n_games --;
}
void loose(pair<int, int> game){
n_games ++;
games[game] = 3;
scores[(game.second - 1)] += 3;
chances();
games[game] = 0;
scores[game.second - 1] -= 3;
n_games --;
}
void tie(pair<int, int> game){
n_games ++;
games[game] = 2;
scores[(game.first - 1)] += 1;
scores[(game.second - 1)] += 1;
chances();
games[game] = 0;
scores[game.first - 1] -= 1;
scores[game.second - 1] -= 1;
n_games --;
}
void chances(){
// if all games have been played
if (n_games == 6){
c = 0;
for (int score : scores){
if (score >= scores[favorite-1]) c++;
}
if (c == 1){
sum ++;
}
return;
}
// for every game that' not played, play it with the three possible outcomes
for (auto game : games){
if (game.second == 0){
win(game.first);
tie(game.first);
loose(game.first);
return;
}
}
}
int main() {
// 0 = not played, 1 = first team won, 2 = tie, 3 = second team won
games[pair<int, int>(1, 2)] = 0;
games[pair<int, int>(1, 3)] = 0;
games[pair<int, int>(1, 4)] = 0;
games[pair<int, int>(2, 3)] = 0;
games[pair<int, int>(2, 4)] = 0;
games[pair<int, int>(3, 4)] = 0;
cin >> favorite >> n_games;
for (int i=0; i<n_games; i++){
// getting input
cin >> t1 >> t2 >> s1 >> s2;
if (s1 > s2){
games[pair<int, int>(t1, t2)] = 1;
scores[t1-1] += 3;
} else if (s1 == s2){
games[pair<int, int>(t1, t2)] = 2;
scores[t1-1] ++;
scores[t2-1] ++;
} else{
games[pair<int, int>(t1, t2)] = 3;
scores[t2-1] += 3;
}
}
chances();
cout << sum << endl;
}