【贪心】Souvenir

入门题

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的形式

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值