Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Chess Match CodeChef Solution

Problem – Chess Match CodeChef Solution

In a Chess match “a + b”, each player has a clock which shows a minutes at the start and whenever a player makes a move, b 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 N turns (i.e. {N+1}{2} moves made by white and {N}{2} moves made by black), the game ends and the clocks of the two players stop; they show that the players (white and black) have A and B seconds left respectively. Note that after the N-th turn, b=2 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 T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains three space-separated integers NA and B.

Output

For each test case, print a single line containing one integer — the duration of the game.

Constraints

  • 1≤T≤105
  • 10≤N≤100
  • 0≤A≤180+2⋅⌊2N+1​⌋
  • 0≤B≤180+2⋅⌊2N​⌋
  • for N odd, A≥2
  • for N even, B≥2
  • there is at least one valid game consistent with the input

Sample 1:

Input:
3
10 0 2
11 2 1
12 192 192
Output: 
378
379
0

Explanation:

Example case 1: The total time given to both clocks after 10 turns is 2⋅(180+10)=380 seconds. The total time left at the end is 0+2=2 seconds. The duration of the game is 380−2=378 seconds.

Example case 3: The total time given to both clocks after 12 turns is 2⋅(180+12)=384 seconds. The total time left at the end is 192+192=384 seconds. The duration of the game is 384−384=0 seconds.

Chess Match CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	int t; 
	cin>>t;
	while(t--){
	    int n, a, b;
	    cin>>n>>a>>b;
	    
	    int tt , tiL;
	    tt  = 2*(180 + (n));
	    tiL = a+b;
	    
	    cout<<tt-tiL<<endl;
	}
	return 0;
}

Chess Match CodeChef Solution in Pyth 3

T=int(input())

for t in range(T):
    N,A,B = map(int,input().split(' '))
    total=2*(180+N)
    time=A+B
    dur=total-time
    print(dur)
    
    

Chess Match CodeChef Solution in Java


import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0;i<t;i++){
		    int n =sc.nextInt();
		    int a=sc.nextInt();
		    int b =sc.nextInt();
		    int ans =2*(180+n);
		    System.out.println(ans-(a+b));
		}
	}
}
Chess Match CodeChef Solution Review:

In our experience, we suggest you solve this Chess Match CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Chess Match CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Chess Match CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

Microsoft Learn

CodeChef Solution

Leave a Reply

Your email address will not be published. Required fields are marked *