#P10582. [蓝桥杯 2024 国 A] 最强策略家

[蓝桥杯 2024 国 A] 最强策略家

Problem Description

In an intellectual board game, two players, Xiao Lan and Xiao Qiao, need to operate on an n×nn \times n matrix whose initial values are all 00, in order to show their wisdom and strategy and determine who is the strongest strategist.

The rules are as follows:

  • Xiao Lan moves first. After he finishes his move, it is Xiao Qiao’s turn, then Xiao Lan’s turn again, and so on alternately.
  • On each of Xiao Lan’s turns, he can choose 22 elements in the matrix and change the values of these elements to 11.
  • On Xiao Qiao’s 11-st turn, he can choose a 1×11 \times 1 submatrix and reset all elements in that submatrix to 00. On Xiao Qiao’s 22-nd turn, he can choose a 2×22 \times 2 submatrix and reset all elements in that submatrix to 00. By analogy, on Xiao Qiao’s ii-th turn, he can choose an i×ii \times i submatrix and reset all elements in that submatrix to 00.
  • After both sides have each made nn moves, the game ends.

Let XX be the maximum number of elements with value 11 that ever appears during the entire game.

Xiao Lan tries to maximize XX, while Xiao Qiao tries to minimize XX.

Assuming both players have perfect logical reasoning ability and always take the best strategy, what will XX be (that is, what is the maximum number of elements with value 11 during the whole game)?

Input Format

The first line contains an integer TT, representing the number of test cases.

The next TT lines each contain an integer nn, representing the size of the matrix.

Output Format

For each test case, output one line containing an integer, representing the answer.

2
2
5
3
5

Hint

[Sample Explanation]

In the first sample, Xiao Lan and Xiao Qiao take turns operating on a 2×22 \times 2 matrix.

Initial matrix state:

[0000]\begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}

Xiao Lan’s 1st turn: Change two elements with value 00 to 11. A possible state is:

[1100]\begin{bmatrix} 1 & 1 \\ 0 & 0 \end{bmatrix}

Xiao Qiao’s 1st turn: Xiao Qiao can only choose a 1×11 \times 1 submatrix to reset the element to 00. In order to minimize the number of elements with value 11, Xiao Qiao needs to reset one element that is already 11 to 00. A possible state is:

[0100]\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}

Xiao Lan’s 2nd turn: Xiao Lan again changes two elements with value 00 to 11. A possible state is:

[1110]\begin{bmatrix} 1 & 1 \\ 1 & 0 \end{bmatrix}

Xiao Qiao’s 2nd turn: Xiao Qiao can choose a 2×22 \times 2 submatrix (that is, the whole matrix) and reset all values to 00.

[0000]\begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}

Therefore, when both sides use the best strategy, the maximum number of elements with value 11 in the matrix can reach 33.

[Constraints and Notes for Testcases]

For 30%30\% of the test cases, 1T1031 \le T \le 10^3, 1n1031 \le n \le 10^3.
For all test cases, 1T1051 \le T \le 10^5, 1n1091 \le n \le 10^9.

Translated by ChatGPT 5