QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#9376. 游戏

统计

Alice 和 Bob 正在玩一个游戏。初始时,Alice 有 $x$ 个筹码,Bob 有 $y$ 个筹码。

游戏进行若干轮。在每一轮中,Alice 获胜的概率为 $p_0$,Bob 获胜的概率为 $p_1$,平局的概率为 $1 - p_0 - p_1$。

如果出现平局,游戏立即进入下一轮。否则,如果获胜者的筹码数不小于失败者的筹码数,则获胜者赢得整个游戏,游戏结束;否则,失败者失去与获胜者当前筹码数相等的筹码,游戏进入下一轮。

注意,在游戏的每一轮之后,没有任何人的筹码会增加。

你需要求出 Alice 最终赢得整个游戏的概率。

输入格式

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

对于每个测试用例,第一行包含两个整数 $x$ 和 $y$ ($1 \le x, y \le 10^9$),分别表示 Alice 和 Bob 初始拥有的筹码数。

第二行包含三个非负整数 $a_0, a_1$ 和 $b$ ($1 \le a_0 + a_1 \le b < 998244353$),表示 $p_0 = \frac{a_0}{b}, p_1 = \frac{a_1}{b}$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示 Alice 赢得整个游戏的概率,对 $998244353$ 取模。

样例

样例输入 1

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

样例输出 1

499122177
910398850
220911476

说明

对于第一个测试用例,由于两位玩家拥有相同数量的筹码且赢得一轮的概率相同,因此 Alice 或 Bob 赢得整个游戏的概率均为 $\frac{1}{2}$。

对于第二个测试用例,Alice 必须在 Bob 赢得一轮之前先赢得三轮才能赢得整个游戏。如果一轮没有以平局结束,Alice 获胜的概率为 $\frac{2}{5}$,因此 Alice 最终获胜的概率为 $(\frac{2}{5})^3 = \frac{8}{125}$。

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.