链接:
2240. 买钢笔和铅笔的方案数
题意:
一共total元,两种笔分别cost1和cost2元,求能买的的笔的所有情况,不要求花光钱
解:
枚举其中一个数字就行
实际代码:文章来源:https://www.toymoban.com/news/detail-688583.html
#include<bits/stdc++.h>
using namespace std;
long long waysToBuyPensPencils(int total, int cost1, int cost2)
{
long long a=total/cost1,b=(total-a*cost1)/cost2,ans=0;
while(a>=0)
{
ans+=b+1;
a--;
b=(total-a*cost1)/cost2;
}
cout<<ans<<endl;
return ans;
}
int main()
{
int total,cost1,cost2;
cin>>total>>cost1>>cost2;
long long ans=waysToBuyPensPencils(total,cost1,cost2);
cout<<ans<<endl;
}
限制:文章来源地址https://www.toymoban.com/news/detail-688583.html
1 <= total, cost1, cost2 <= 106
到了这里,关于2023-09-01力扣每日一题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!