QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15357. 孤独的角斗士

Statistiques

你名震四方的独特战斗风格使你成为了一名传奇的孤独角斗士。现在,你正站在大竞技场的中央。为了赢得自由,你必须在决斗中击败两位卫冕冠军 $B$ 和 $C$。这不是一场混乱的大混战,而是一系列有条不紊的决斗。

你开始时拥有 $a$ 点生命值(HP)。第一位冠军 $B$ 拥有 $b$ 点 HP,第二位冠军 $C$ 拥有 $c$ 点 HP。战斗按照以下规则展开:

  1. 混战阶段(3名参与者):只要你、$B$ 和 $C$ 都还站着(即三人的 HP 都 $> 0$),战斗就会按轮进行。每一轮由两次连续的交锋组成:

    • 首先,你与冠军 $B$ 战斗。
    • 其次,你与冠军 $C$ 战斗。

    只要你们三人都还活着,这个(你对 $B$,然后你对 $C$)的循环就会一直重复。

  2. 决斗阶段(2名参与者):如果在任何时候有一位冠军被击败(其 HP 降至 $0$ 或更低),战斗结构就会发生变化。你将与剩下的那位冠军进入一场一对一的生死决斗。你将与这唯一的对手不断战斗,直到你们其中一人被击败。

战斗机制

  • 在任何一次交锋中,总会分出胜负。胜者从败者身上吸取 $1$ 点 HP。也就是说,胜者的 HP 增加 $1$,败者的 HP 减少 $1$。
  • 你的战斗风格很奇特。你在交锋中获胜的概率取决于对手:

    • 你战胜冠军 $B$ 的概率为 $p$。
    • 你战胜冠军 $C$ 的概率为 $1 - p$。

胜负判定

  • 当且仅当你想办法击败了两位冠军(即 $B$ 和 $C$ 的 HP 都变为 $0$)时,你才获得胜利。
  • 如果你的 HP 达到 $0$,你就被击败了。审判立即结束。

给定你的初始 HP $a$,冠军们的 HP $b$ 和 $c$,以及你对冠军 $B$ 的获胜概率 $p$,你最终成为唯一胜者的总概率是多少?

答案可以表示为分数 $\frac{P}{Q}$。你应该输出该值模 $M = 10^9 + 7$ 的结果。这可以通过 $(P \cdot Q^{-1}) \pmod M$ 来计算,其中 $Q^{-1}$ 是 $Q$ 关于 $M$ 的模逆元。题目数据保证 $Q \not\equiv 0 \pmod M$,因此该逆元总是存在。

输入格式

输入的第一行包含一个整数 $T$ ($1 \le T \le 10^4$),表示测试用例的数量。

对于每个测试用例,单行包含五个整数 $a, b, c, u$ 和 $v$,其中 $p = u/v$ ($1 \le a, b, c, u, v \le 10^8$,$a + b + c$ 为奇数且 $u < v$)。

输出格式

对于每个测试用例,输出一个整数,表示所求的值。

样例

输入样例 1

2
1 2 2 4 5
3 3 1 1 5

输出样例 1

551319652
915033883

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.