一道简单的贪心
题意简单来说,就是有两种操作:
1.给a加上k 2.给a乘上k
问你最少多少次操作可以使ab
其实就是比a+k和a*k谁能让a变得更大
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,k;
cin>>a>>b>>k;
int sum=0;//统计操作数
while(a<b){
if(a+k>a*k){//比较
a+=k;
}else{
a*=k;
}
sum++;
}
cout<<sum<<endl;//输出
return 0;
}