Buying Torches

题目描述

You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft kk torches. One torch can be crafted using one stick and one coal.

Hopefully, you've met a very handsome wandering trader who has two trade offers:

  • exchange 11 stick for xx sticks (you lose 11 stick and gain xx sticks).
  • exchange yy sticks for 11 coal (you lose yy sticks and gain 11 coal).

During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order.

Your task is to find the minimum number of trades you need to craft at least kk torches. The answer always exists under the given constraints.

You have to answer tt independent test cases.

输入格式

The first line of the input contains one integer tt ( 1 \le t \le 2 \cdot 10^41≤t≤2⋅104 ) — the number of test cases. Then tt test cases follow.

The only line of the test case contains three integers xx , yy and kk ( 2 \le x \le 10^92≤x≤109 ; 1 \le y, k \le 10^91≤y,k≤109 ) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively.

输出格式

For each test case, print the answer: the minimum number of trades you need to craft at least kk torches. The answer always exists under the given constraints.

题意翻译

题目描述:

你要获得 kk 个火把,最开始你有 11 根木棒。一个木棒和一个煤炭可以合成一个火把,你也可以通过两种交易方式得到木棒或煤炭:

  1. 通过商人 11 根木棒,获得 xx 根木棒。
  2. 通过商人 yy 根木棒,获得 11 个煤炭。

其中 2\leq x\leq 10^{9};1\leq y,k\leq 10^{9}2≤x≤109;1≤y,k≤109。

求得到 kk 个火把的最少交易次数。

输入输出样例

输入 #1复制

5
2 1 5
42 13 24
12 11 12
1000000000 1000000000 1000000000
2 1000000000 1000000000

输出 #1复制

14
33
25
2000000003
1000000001999999999

代码

#include <stdio.h>
int main()
{
	long long int n;
	scanf ("%lld",&n);
	for (long long int i=0;i<n;i++) {
		long long int x,y,k;
		scanf ("%lld %lld %lld",&x,&y,&k);
		long long int sc=(y*k+k-1)/(x-1)+k;
		if ((y*k+k-1)%(x-1)!=0) {    //若不能整次换完,则再换1次
			sc++;
		}
		printf ("%lld\n",sc);
	}
	return 0;
}

思路:

1木棒=x木棒   -即每次交易获得(x-1)根木棒

y木棒=1煤炭

1木棒+1煤炭=1火把

先算总共需要多少木棒,其中有分用来换煤炭和用来合成火把的木棒,k根火把需要k*y根木棒来换取k煤炭,还需k根木棒用来合成火把,初始1根木棒,即还需(k-1)根木棒,那么就是除了初始的一根木棒,需换k*y+(k-1)根木棒,换取这些木棒需要交易 ( k * y + k - 1 ) / ( x - 1 )  次,再加上其中换煤炭的次数,最少交易次数即为( k * y + k - 1 ) / ( x - 1 )+k 次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值