Chess Match Problem of CodeChef
Although this problem was a fairly easy one and it took just 3 mins to submit the code and pass all the test cases, this was an interesting problem to an extent because it needs a bit of thinking by considering the scenario of making a move in a Chess Game, here it took the case of a 3+2 blitz match, where we just had to think that on making a move after taking 5 seconds in real-time, actually the clock will show that we took just 3 seconds because of the increment of 2 seconds on each move. So by just having an understanding of this idea, we can easily crack this problem. All other things mentioned in the problem statement, like the number of moves played by both players, and that the last player that made the move also gets a 2 second increment can be ignored because, firstly... we just care about the number of moves played, that is, N, and the increment that was given for those N moves, so we don't care about the number of moves played by any of the players, and secondly we are taking the total increment as N*2 seconds, so we are considering that the last move also gave an increment of 2 seconds, so that is also considered by us, both of these things are just to make this problem intricate.
This problem is also interesting because this can be tinkered and manipulated to make some other problem statement out of this, like finding the number of moves played by both the players after N number of moves, so that would just require an understanding that obviously white will have 1 move extra for odd number of moves, while for even, suppose 10 moves both players will have played 5-5 moves, and for 11 number of moves, white has made 11/2, that is 5+1 moves, whereas black has made 11/2, that is 5 moves, total comes out to be 11. And lastly, this problem can be asked like, after N moves tell the time(in real-time) taken by each of the players. So, this will require that information like the number of moves played by each players separately so that we can calculate the time taken by both of them, like the time taken according to the clock for both players individually + the time given as increment to white(2*6 seconds, assume) and that to black(2*5, assume). So, these can be the variations of this problem that would increase the complex nature to an extent but would still be kind of an easy level.
The code that passed all the Test Cases is mentioned below the problem statement, the code is very succinct because of Python's way of taking inputs and the fairly simple way of Python, try to do it on your own before seeing the solution.
Problem
Read problem statements in Mandarin Chinese, Russian, and Vietnamese as well.
In a Chess match "a + b", each player has a clock which shows minutes at the start and whenever a player makes a move, seconds are added to this player's clock. Time on a player's clock decreases during that player's turns and remains unchanged during the other player's turns. If the time on some player's clock hits zero (but not only in this case), this player loses the game.
There's a 3 + 2 blitz chess match. After turns (i.e. moves made by white and moves made by black), the game ends and the clocks of the two players stop; they show that the players (white and black) have and seconds left respectively. Note that after the -th turn, seconds are still added to the clock of the player that made the last move and then the game ends.
Find the total duration of the game, i.e. the number of seconds that have elapsed from the start of the game until the end.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains three space-separated integers , and .
Output
For each test case, print a single line containing one integer — the duration of the game.
Constraints
- for odd,
- for even,
- there is at least one valid game consistent with the input
Sample 1:
3 10 0 2 11 2 1 12 192 192
378 379 0
Explanation:
Example case 1: The total time given to both clocks after turns is seconds. The total time left at the end is seconds. The duration of the game is seconds.
Example case 3: The total time given to both clocks after turns is seconds. The total time left at the end is seconds. The duration of the game is seconds.
Comments
Post a Comment