A coin game

3.6

25 votes
Very-Easy
Problem

Sameer and Bhuvan love to play with coins.One day they decided to play a game in which Sameer will give Bhuvan N coins numbered from 1 to N, and all coins will be facing in same direction(Either heads or tails). Bhuvan needs to play N rounds.In the k-th round he will flip the face of all the coins whose number is less than or equal to k i.e., face of coin i will be changed from Head to Tail,or Tail to Head(i<=k). After N round Sameer will ask total number of coins showing a particular face.Help Bhuvan to find out the answer.

Input:

The first line of input contains an integer T, denoting the number of test cases.Then T test cases follow.

The first line of each test contains an integer R, denoting the number of games to be played by Bhuvan. Each of the following R lines denotes a single game, and contains 3 space separated integers X, N, Y, where X denotes the initial state of the coins, N denotes the number of coins and rounds, and Y, which is either 1, or 2 as explained below.

Here X=1 means all coins are showing Head in the start of the game, and X=2 means all coins are showing Tail in the start of the game. Y=1 means Bhuvan needs to guess the total number of coins showing Head in the end of the game, and Y=2 means Bhuvan needs to guess the total number of coins showing Tail in the end of the game.

Output:

For each game, output one integer denoting the total number of coins showing the particular face in the end of the game.

Constraints:

1 ≤ T ≤ 10

1 ≤ R ≤ 20000

1 ≤ N ≤ 10^4

1 ≤ X ≤ 2

1 ≤ Y ≤ 2

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Here X=1, so initial arrangement of coins are H H H H H, and now Bhuvan will play 5 rounds and coin faces will be changed as follows

After the 1st Round: T H H H H

After the 2nd Round: H T H H H

After the 3rd Round: T H T H H

After the 4th Round: H T H T H

After the 5th Round: T H T H T

Finally Y=1, so we need to find the total number of coins showing Head, which is 2.

In the 2nd game in Example: This is similar to the 1st game, except he needs to find the total number of coins showing Tail. So the Answer is 3.

Editor Image

?