入门题
Today is the 1st anniversary of BestCoder. Soda, the contest manager, wants to buy a souvenir for each contestant. You can buy the souvenir one by one or set by set in the shop. The price for a souvenir is p yuan and the price for a set of souvenirs if q yuan. There’s m souvenirs in one set.
There’s n contestants in the contest today. Soda wants to know the minimum cost needed to buy a souvenir for each contestant.
题意:
一个纪念品p元,一套纪念品q元,一套里有m个。
一共有n个人。
求需要花的最低费用
input:
t组样例(1<=t<=1e5)
每组输入 n,m,p,q;
output:
输出总花费
ll t,n,m,p,q;
int main(){
cin>>t;
while(t--){
cin>>n>>m>>p>>q;
if(q>=p*m){
cout<<n*p<<endl;
}else{
ll z=n/m;
ll cost= z*q;
ll last=n-z*m;
if(last*p >=q){
cout<<cost+q<<endl;
}else{
cout<<cost+last*p<<endl;
}
}
}
return 0;
}
如果一套的价格比起单价并不便宜的话,那就按照单价p买,
要不然,如果买整套更便宜
______那就先看那么多人可以买几套,
______先算出这些人的花费。
______然后还要判断下 剩下的这几个人单买纪念品贵,还是直接再买一整套贵。
注意点:
1.注意是否又调用了中途已被改变的变量
2.注意用q>=p*m的形式做判断,不要用q/m>=p的形式