CF2155A.El fucho

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Juan and his friends are going to split themselves into nn teams and play a modified double-elimination football tournament, consisting of a winners' group and a losers' group. Initially, all teams belong to the winners' group.

In each round of the tournament, the following happens as long as one of the groups has at least two teams:

  • All teams in the winners' group pair up.
    • If there is an odd number of teams in the winners' group, there would be a team that didn't get paired up (and wouldn't play a match). That team stays in the winners' group.
    • For teams in the winners' that got paired up, each pair plays a football match in which there are no ties.
      • If a team wins, it stays in the winners' group.
      • If a team loses, it drops down to the losers' group in the next round.
  • All teams in the losers' group pair up.
    • If there is an odd number of teams in the losers' group, there would be a team that didn't get paired up (and wouldn't play a match). That team stays in the losers' group.
    • For teams in the losers' that got paired up, each pair plays a football match in which there are no ties.
      • If a team wins, it stays in the losers' group.
      • If a team loses, it gets eliminated from the tournament.

Note that in the above process, when a team loses a match in the winners' group, it drops down to the losers' group in the next round. That means, it is not considered for the pairing process in the current round's losers' group.

After multiple iterations of the aforementioned process, both groups end up with a single team each. When this happens, both teams face off against each other in a match and a victor emerges.

Determine how many matches were played in total. It can be proved that no matter how the teams are paired up and which ones win and lose, the answer remains the same.

胡安和他的朋友们将分成 nn 支队伍,进行一场改良版的双败淘汰制足球锦标赛,该锦标赛包含“胜者组”和“败者组”。初始时,所有队伍均属于胜者组。

在锦标赛的每一轮中,只要其中任一组至少包含两支队伍,以下过程便会持续进行:

  • 胜者组中的所有队伍两两配对:
    • 若胜者组中队伍数量为奇数,则会有一支队伍无法配对(不参加比赛),该队留在胜者组中。
    • 对于已配对的胜者组队伍,每对之间进行一场足球比赛,且比赛无平局。
      • 若某队获胜,则其保留在胜者组中;
      • 若某队落败,则其将在下一轮降入败者组。
  • 败者组中的所有队伍两两配对:
    • 若败者组中队伍数量为奇数,则会有一支队伍无法配对(不参加比赛),该队留在败者组中。
    • 对于已配对的败者组队伍,每对之间进行一场足球比赛,且比赛无平局。
      • 若某队获胜,则其保留在败者组中;
      • 若某队落败,则其直接被淘汰出锦标赛。

注意:在上述过程中,当一支队伍在胜者组比赛中失利时,它将在下一轮才进入败者组。这意味着,它不参与本轮败者组的配对过程。

经过若干轮上述操作后,胜者组与败者组最终各仅剩一支队伍。此时,这两支队伍进行一场决赛,决出最终冠军。

请计算整个锦标赛中总共进行了多少场比赛。可以证明:无论队伍如何配对、也无论各场比赛胜负结果如何,该总数恒定不变。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The only line of each test case contains one positive integer nn (2≤n≤5002 \le n \le 500) — the number of teams.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是测试用例的描述。

每个测试用例仅有一行,包含一个正整数 nn(2≤n≤5002 \le n \le 500)—— 表示队伍的数量。

输出格式

For each test case, print the total number of matches played during the tournament.

对于每个测试用例,输出锦标赛期间进行的比赛总场数。

输入输出样例

  • 输入#1

    2
    2
    3

    输出#1

    2
    4

说明/提示

In the first test case, it can be proved that exactly 22 matches are played before a victor is declared.

In the second test case, the image below shows one possible tournament. Notice that 44 matches were played in total.

在第一个测试用例中,可以证明在宣布获胜者之前恰好进行了 22 场比赛。

在第二个测试用例中,下方图片展示了一种可能的锦标赛安排。注意,总共进行了 44 场比赛。

输入解题思路,AI测评打分。不知道怎么写?

首页