费用流之网格图模型

Monocarp is playing a MMORPG. There are two commonly used types of currency in this MMORPG — gold coins and silver coins. Monocarp wants to buy a new weapon for his character, and that weapon costs �n silver coins. Unfortunately, right now, Monocarp has no coins at all.

Monocarp can earn gold coins by completing quests in the game. Each quest yields exactly one gold coin. Monocarp can also exchange coins via the in-game trading system. Monocarp has spent days analyzing the in-game economy; he came to the following conclusion: it is possible to sell one gold coin for �a silver coins (i. e. Monocarp can lose one gold coin to gain �a silver coins), or buy one gold coin for �b silver coins (i. e. Monocarp can lose �b silver coins to gain one gold coin).

Now Monocarp wants to calculate the minimum number of quests that he has to complete in order to have at least �n silver coins after some abuse of the in-game economy. Note that Monocarp can perform exchanges of both types (selling and buying gold coins for silver coins) any number of times.

Input

The first line contains one integer �t (1≤�≤1041≤t≤104) — the number of test cases.

Each test case consists of one line containing three integers �n, �a and �b (1≤�≤1071≤n≤107; 1≤�,�≤501≤a,b≤50).

Output

For each test case, print one integer — the minimum possible number of quests Monocarp has to complete.

Sample 1

Inputcopy

Outputcopy

4

100 25 30

9999997 25 50

52 50 48

49 50 1

4

400000

1

1

Note

In the first test case of the example, Monocarp should complete 44 quests, and then sell 44 gold coins for 100100 silver coins.

In the second test case, Monocarp should complete 400000400000 quests, and then sell 400000400000 gold coins for 1010 million silver coins.

In the third test case, Monocarp should complete 11 quest, sell the gold coin for 5050 silver coins, buy a gold coin for 4848 silver coins, and then sell it again for 5050 coins. So, he will have 5252 silver coins.

In the fourth test case, Monocarp should complete 11 quest and then sell the gold coin he has obtained for 5050 silver coins.

#include<iostream>

using namespace std;

int main()

{

int t,a,b,n;

cin>>t;

while(t--)

{

cin>>n>>a>>b;

if(a>b)

{

cout<<1<<endl;

}

else

{

cout<<(n+a-1)/a<<endl;

}

}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值