0
点赞
收藏
分享

微信扫一扫

A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)

原题链接:​​http://codeforces.com/contest/1418/problems​​​A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_#define
测试样例

input
5
2 1 5
42 13 24
12 11 12
1000000000 1000000000 1000000000
2 1000000000 1000000000
output
14
33
25
2000000003
1000000001999999999

题意: 你起初有一根木棒,你可以进行两种交易:

  • 你可以用一根木棒兑换A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_i++_02根木棒
  • 你可以用A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_i++_03根木棒兑换一个煤

用一根木棒和一个煤即可形成一个火炬,起初你有一根木棒,现在你需要制造A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_cf_04根木棒,问你需要进行的最少交易次数。

解题思路: 一定要读懂题,读懂了题秒过的。此题基于贪心算法,我们知道,我们需要的是木棒(对于煤而言,它也是需要木棒来制造的,且最少需要A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_ios_05根,进行的最少交易次数为A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_#define_06,那么关键在于木棒了,我们大概知道我们要获取多少根木棒了,即:A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_#define_07根,那么知道这个我们自然就好做了,每次利用第一个交易增加了A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_cf_08根,故我们只需要判断我们至少要进行多少次交易才能超过我们需要的木棒根数:A. Buying Torches(贪心水题)Educational Codeforces Round 95 (Rated for Div. 2)_#define_07根。(注意:起初有一根)。OK,具体看代码。

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

ll t,x,y,k;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>x>>y>>k;
ll ans=k*y+k;
ans-=x;x--;
if(ans<=0){
cout<<1+k<<endl;
continue;
}
ll temp=ans/x;
if(ans==temp*x){
cout<<temp+1+k<<endl;
}
else{
cout<<temp+2+k<<endl;
}
}
}
return 0;
}


举报

相关推荐

0 条评论