#P9156. 「GLR-R4」芒种

    ID: 9761 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>洛谷原创Special JudgeO2优化洛谷月赛

「GLR-R4」芒种

Background

  "Clear clouds gently ripple, warm winds without waves, raising a cup to escape the heat as people gather."


  "It’s the week of the Gaokao..."

  There was no pressure to fight for a venue today, but no one even dared to leave the training room, because the teaching building across the way was the Gaokao exam site.

  "Maybe next year we’ll be over there." Although the afternoon training was over, the cafeteria had a special schedule today, so Tianyi and A-Ling still had to cuddle in the lounge for quite a while.

  "A-Ling, hungry..." As if she could not hear any topic other than food, Tianyi lay on the sofa, twirling her fingers through her hair—through A-Ling’s hair—and complaining.

  "Let’s play a game."


  Mangzhong "Icy soda, the restless bubbles all melt away.
 Let the lazy wind seize the chance and slip in."

Problem Description

  Double Neurasthenia is a card game that tests memory heavily. The rules are as follows.

  There are nn different types of cards, two cards of each type. Initially, all 2n2n cards are placed face down on the table. Two players take turns. In each move, the player chooses two different cards and flips them up at the same time. These two cards are shown to both players, and then:

  • If the two cards are of the same type, the player gains 11 point and takes these two cards away. The next move is still made by the current player.

  • Otherwise, the player turns these two cards face down again. The next move is made by the other player.

  The game ends when all cards have been taken away.

  Both players aim to maximize their final scores. In addition, if both sides agree, they may choose to draw. Suppose there are still 2n2n' cards left when they draw; then each side gets n/2n'/2 points, and the game ends. To avoid the game never ending, we assume: when choosing a draw is one of the optimal choices for both sides, they will draw immediately.


  Now, A-Ling and Tianyi want to play this game. Because she is too hungry, Tianyi, who is responsible for arranging the cards, accidentally placed mm of the 2n2n cards face up. The types of these mm cards are pairwise distinct. Both sides secretly memorized their types and positions, turned them face down again, and then started the game. We assume Tianyi and A-Ling have perfect memory and are extremely smart: they can remember the type and position of every card that has ever been shown (including the initial mm cards), and they will both use optimal strategies to maximize their expected scores. As the first player, A-Ling wants to know her expected score. Can you help her?

  Since they really are going to cuddle in the lounge for quite a while, you need to compute the answer for TT test cases of (n,m)(n,m).

Input Format

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

The next TT lines each contain two integers n,mn,m, representing the number of card types in this game and the number of cards that were flipped up in advance and then turned face down again.

Output Format

Output TT lines. Each line contains one real number, the answer for that test case. Your output is considered correct if and only if the relative error or absolute error compared with the standard answer does not exceed 10610^{-6}.

4
1 0
2 1
2 2
3 3
1.000000
1.333333
1.000000
1.500000

Hint

Explanation for Sample #1

For the first test case, the pair of cards flipped by the first player must be of the same type, so they take them away and the game ends. The first player’s expected score is 11.

For the third test case, it can be proven that both sides will agree to draw at the start of the game. The expected scores of the first and second players are both 11.

Constraints

For 100%100\% of the data, 1n5×1031\le n\le 5\times10^3, 0mn0\le m\le n.

For different subtasks, the constraints are as follows:

Subtask ID n,mn,m TT Special Property Score
11 2\le2 5\le5 None 1010
22 8\le8 44\le44 2020
33 5×103\le5\times10^3 5×103\le5\times10^3 Yes 1010
44 =1=1 None 2020
55 5×103\le5\times10^3 4040
  • Special Property: n=mn=m.

Translated by ChatGPT 5