The Wooden Plates Solution

Problem

You and your pal are playing a jumping game. There are N wooden plates in a row (where N is an odd number). You jump into plate 1, and your friend jumps into plate N. Then you jump into plate 2, and your friend follows you into plate N-1, and so on.

The procedure comes to an end when someone is unable to make the following jump because the plate is occupied by someone else. Locate the last plate to be jumped into.

Input Format

  • The first line comprises an integer T, which represents the number of test cases. Then come the test cases.
  • Each test case has a single line of input, containing a single number N.

Output Format

For each test case, output in a single line the answer to the problem.

Constraints

  • 1 \leq T \leq 10^5
  • 1 \leq N \lt 2\cdot 10^5
  • N is odd

Subtasks

Subtask #1 (100 points): original constraints

Sample 1:

Input
Output
2
1
3
1
2

Explanation:

Test Case 1: Since there is only 1 plate, that's the only one to be jumped into.

Test Case 2: The first player jumps into plate 1. The second player jumps into plate 3 and finally, the first player jumps into plate 2. Then the second player cannot make another jump, so the process stops.




Program :

 import java.util.*;

import java.lang.*;

class  Wooden

{

public static void main(String[] args)

{

int t,n;

Scanner es=new Scanner(System.in);

t=es.nextInt();

for(int i=0;i<t;i++)

{

n=es.nextInt();

System.out.println((n/2)+1);

}

}


}

Post a Comment

0 Comments