郑州网站顾问,目录做排名 网站,怎么确认网站是什么语言做的,短信轰炸网站开发链接#xff1a;
2240. 买钢笔和铅笔的方案数
题意#xff1a;
一共total元#xff0c;两种笔分别cost1和cost2元#xff0c;求能买的的笔的所有情况#xff0c;不要求花光钱
解#xff1a;
枚举其中一个数字就行
实际代码#xff1a;
#includebits/stdc.h
2240. 买钢笔和铅笔的方案数
题意
一共total元两种笔分别cost1和cost2元求能买的的笔的所有情况不要求花光钱
解
枚举其中一个数字就行
实际代码
#includebits/stdc.h
using namespace std;
long long waysToBuyPensPencils(int total, int cost1, int cost2)
{long long atotal/cost1,b(total-a*cost1)/cost2,ans0;while(a0){ansb1;a--;b(total-a*cost1)/cost2;}coutansendl;return ans;
}
int main()
{int total,cost1,cost2;cintotalcost1cost2;long long answaysToBuyPensPencils(total,cost1,cost2);coutansendl;
}限制
1 total, cost1, cost2 106