-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1997 S3.cpp
67 lines (42 loc) · 2.06 KB
/
1997 S3.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
/*
1997 S3 - Double Knockout Competition
Difficulty: Very Easy
This problem is quite easy. For each round, get the total number of matchest between undefeated teams, only half the teams will lose, so subtract them from undefeated and add them to one-loss.
For the one-loss teams, do the same thing, add to defeated and subtract from one-loss. Keep repeating this until you reach the special round.
Afterwards, you can hardcode the end.
*/
#include <iostream>
int main(){
int n;
std::cin >> n;
for (int i = 0; i < n; i++){
int t;
std::cin >> t;
//Initial statement
std::cout << "Round 0: " << t << " undefeated, 0 one-loss, 0 eliminated" << '\n';
int undefeated = t, oneloss = 0, eliminated = 0;
int round = 1;
//Keep looping until special round
while (undefeated > 1 || oneloss > 1){
int losers, eliminate;
losers = undefeated / 2; //Number of undefeated teams that will lose
eliminate = oneloss / 2; //Number of one-loss teams that will be eliminated
undefeated -= losers;
oneloss += losers;
oneloss -= eliminate;
eliminated += eliminate;
//Output info
std::cout << "Round " << round << ": " << undefeated << " undefeated, " << oneloss << " one-loss, " << eliminated << " eliminated" << '\n';
round++;
}
//Hardcode the rest
undefeated -= 1; oneloss += 1;
std::cout << "Round " << round << ": " << undefeated << " undefeated, " << oneloss << " one-loss, " << eliminated << " eliminated" << '\n';
round++;
oneloss -= 1;
eliminated++;
std::cout << "Round " << round << ": " << undefeated << " undefeated, " << oneloss << " one-loss, " << eliminated << " eliminated" << '\n';
std::cout << "There are " << round << " rounds." << '\n'; //Remember to terminate with new line, if you don't you will get presentation error.
}
return 0;
}