ACPC10E - Sometimes, a penalty is good!
FIFA is considering a few changes to the way it organizes the Football World Cup. Currently, 32 teams compete for the World Title in two stages. During the first stage, known as the groups stage, the 32 teams are split evenly into 8 groups. Every team in the group plays 3 games, one against each team in their own group. Teams are then ranked within their group according to some points system. During the second (and final) stage, the top two teams from each group advance to the knockout stage where eight games are played to determine eight winners who would then play four games to determine four winners, then two games to determine the two winners who would then play the final game to determine the world champion. Needless to say, for the knockout stage to work, the number of teams in that stage has to be a power of two. FIFA is considering adding more groups, adding more teams to groups, and possibly changing the number of teams advancing from each group to the knockout stage. In addition, FIFA is considering having certain teams (previous champion, host country, etc.) advance to the knockout stage directly (without having to play in the groups stage.) But FIFA needs to know how many games will be played if any of these changes are applied. Please help them!
Your program will be tested on one or more test cases. Each test case is specified on a single line made of 4 natural numbers with the following format:
G T A D
Where (G > 0) is the number of groups; T is the number of teams in each group; A is the number of teams advancing from each group to the knockout stage; and D is the number of teams directly advancing to the knockout stage without going through the groups stage. Note that (0 < A ≤ T) and that the four numbers in the input are no larger than 216.
If the total number of teams in the knockout stage is not a power of two, your program must increase them to the closest power of two.
The last test case is followed by a dummy line made of four -1’s.
For each test case, print:
where G, A, T, and D are as in the input, X is the total number of games, and Y is the number of teams your program determined it must add.
8 4 2 0
8 4 2 1
-1 -1 -1 -1
Notice, no match for 3rd place in this problem.
how can i use log in the programming
log +ceil works..but use round with inbuilt functions like pow
why log will got wa,and ac without log
2^16 is the only thing you need to keep an eye on.. Rest is a piece of cake!!! :)
bitwise is a gods gift :D
pay attention to overflow