链接:
题意:
一共total元,两种笔分别cost1和cost2元,求能买的的笔的所有情况,不要求花光钱
解:
枚举其中一个数字就行
实际代码:
#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;
}
限制:
1 <= total, cost1, cost2 <= 106