Universal Cup Judging System

Universal Cup

Süre Sınırı: 3.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

給定一對非負整數 $W, S$。

海鸚 Pataro 正在獨自玩一個紙牌遊戲。有兩種類型的牌:牌 w 和牌 s。

起初,Pataro 有 $W$ 張 w 類牌和 $S$ 張 s 類牌,且他的分數為 $0$。他反覆從手中的牌消耗一張,直到所有牌都被消耗完為止。當第 $i$ 張被消耗的牌是 s 類牌時,會產生以下效果:

  • 在第 $(i - 1)$ 張、第 $(i - 2)$ 張和第 $(i - 3)$ 張被消耗的牌當中,設 $x$ 為其中 w 類牌的數量。他獲得 $27 \times \left(\frac{4}{3}\right)^x$ 的分數。

為方便起見,假設在位置 $0$ 或更早位置消耗的牌不是 w 類牌。

請找出 Pataro 透過以適當順序消耗紙牌所能獲得的最大總分數。可以證明,所求答案恆為整數。

請針對 $T$ 組測試資料解決上述問題。

輸入格式

輸入按以下格式給出:

T
case1
case2
:
caseT

每組測試資料按以下格式給出:

W S
  • $1 \le T \le 10^4$
  • $0 \le W, S \le 10^{16}$
  • 所有輸入值皆為整數。

輸出格式

輸出 $T$ 行。 第 $i$ 行應包含第 $i$ 組測試資料的答案。

範例

範例輸入 1

3
5 3
12 9
2026 328

範例輸出 1

160
484
20992

說明

在第一個範例中,Pataro 以 w, w, s, s, w, w, w, s 的順序消耗紙牌是最優的。

  • 第 $3$ 張被消耗的牌是 s 類牌。在第 $2$ 張、第 $1$ 張和第 $0$ 張被消耗的牌中,有 $2$ 張 w 類牌,因此他獲得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 $4$ 張被消耗的牌是 s 類牌。在第 $3$ 張、第 $2$ 張和第 $1$ 張被消耗的牌中,有 $2$ 張 w 類牌,因此他獲得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 $8$ 張被消耗的牌是 s 類牌。在第 $7$ 張、第 $6$ 張和第 $5$ 張被消耗的牌中,有 $3$ 張 w 類牌,因此他獲得 $27 \times \left(\frac{4}{3}\right)^3 = 64$ 分。

因此,Pataro 可以獲得的總分是 $160$。無論如何消耗紙牌,都不可能獲得超過 $160$ 的分數,故答案為 $160$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1484EditorialOpen题解jianglyView
#1342EditorialOpen题解MilmonView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.