Souvenir

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 416    Accepted Submission(s): 270

Problem Description
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.
 
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤105),
indicating the number of test cases. For each test case:



There's a line containing 4 integers n,m,p,q (1≤n,m,p,q≤104).
 
Output
For each test case, output the minimum cost needed.
 
Sample Input
2
1 2 2 1
1 2 3 4
 
Sample Output
1
3
Hint
For the first case, Soda can use 1 yuan to buy a set of 2 souvenirs.
For the second case, Soda can use 3 yuan to buy a souvenir.
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5315 5314 5313 5312 5311 


BestCoder官方解析:
1001 Souvenir

本题是一个简单的数学题. 假设套装优惠的话就尽量买套装, 否则单件买. 注意一下假设一直用套装的话可能在最后的零头不如单买好, 即(n mod m)⋅p<q.



#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int t,n,m,p,q;//单位价格p元,套装q元,一个套装有m个纪念品,总共n个參赛者
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&n,&m,&p,&q);
int price = 0;
if(q/m<p)//假设套装优惠的话尽量买套装
{
if((n%m)*p<q)//假设在买套装最后零头的处理不如单位价格买廉价
{
price = (n/m)*q+(n%m)*p;//就在最后零头买单位价格
}
else
{
price = (n/m+1)*q;//否则多买一个套装
}
}
else//否则直接单位价格买
{
price = n*p;
} printf("%d\n",price);
}
return 0;
}

中文题目在以下:

 

Souvenir

 Accepts: 901
 Submissions: 2743
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 262144/262144 K (Java/Others)
问题描写叙述
今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每一个參赛者准备一个纪念品. 商店里纪念品的单位价格是p元, 同一时候也能够花q元购买纪念品套装, 一个套装里有m个纪念品.

今天总共同拥有n个參赛者, Soda想要知道最少须要花多少钱才干够给每一个人都准备一个纪念品.
输入描写叙述
输入有多组数据. 第一行有一个整数T (1≤T≤105), 表示測试数据组数. 然后对于每组数据:

一行包括4个整数 n,m,p,q (1≤n,m,p,q≤104).
输出描写叙述
对于每组数据输出最小花费.
输入例子
2
1 2 2 1
1 2 3 4
输出例子
1
3
Hint
对于第一组数据, Soda能够1元购买一个套装. 对于第二组数据, Soda能够直接花3元购买一个纪念品.

HDU-5310-Souvenir(C++ &amp;&amp; 简单数学题)的更多相关文章

  1. hdu 5310 Souvenir(BestCoder 1st Anniversary ($))

    http://acm.hdu.edu.cn/showproblem.php?pid=5310 题目大意:要买n个纪念品,可以单个买p元每个,可以成套买q元一套,每套有m个,求最少花费 #include ...

  2. HDU 5310 Souvenir

    Souvenir  Accepts: 901  Submissions: 2743  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 262 ...

  3. hdu 5310 Souvenir (水)

    题意:今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是p元, 同时也可以花q元购买纪念品套装, 一个套装里有m个纪念品.今天总共有n个参 ...

  4. HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  5. HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  7. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  8. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  9. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

随机推荐

  1. 正确的缩写document。querySelector

    北京的夕阳,伴随淡淡的霾殇.从写字楼望去,光线是那么昏黄.没有孤雁,也没有霞光,遥想当年,还是 jQuery 独霸一方.那时的我们,写程序都习惯了使用 $,至少在对美元符号的喜爱上,与 PHP 达成了 ...

  2. Appium + python - automator定位升级版操作

    # coding:utf-8 """参考博客链接:https://www.cnblogs.com/yoyoketang/p/7843819.html"" ...

  3. Integer应该用==还是equals

    问题引出:“Integer应该用==还是equals” 讨论这个问题之前我们先放一段代码 public static void main(String[] args) { Integer a1 = 2 ...

  4. easyui验证提示框 卡在屏幕上!!

    场景:验证提示框,关闭diglog窗口后 还显示在页面中 解决方法: 在窗口关闭事件中,删除提示框(这貌似并不可行),只能将验证提示框隐藏起来. $('#dialog').dialog({ onClo ...

  5. .net core2.0 读取appsettings.json

    一.在start.up中添加注入 二.使用

  6. android.system.ErrnoException: open failed: ENOENT (No such file or directory) 07-19 20:27:45.011 66

    在操作安卓版本23+的文件读取时,不仅要在maniests中声明,还要在代码中动态声明: ; private static String[] PERMISSIONS_STORAGE = { Manif ...

  7. node post和get请求原理

    重要:GET和POST请求他们都是上行请求,都是把数据从浏览器带向服务器的方式, GET 请求实际上就是识别URL中的querystring部分POST请求,一般用来发送大量的内容,此时node非常害 ...

  8. ★Java-----记事本编译、运行时注意事项

    1.文件名需要与源代码中公共类的名字相同,即class后面的名字: 2.Java中严格区分大小写: 3.记事本编辑好之后保存文件后缀必须是". java": 4.运行cmd,dos ...

  9. 复习java基础第二天(异常处理)

    一.常见的异常类型: public class TestException { public static void main(String[] args) { int i = 10; //数学异常: ...

  10. 时序分析:ARIMA模型(非平稳时间序列)

    转载于一篇硕士论文.... ARIMA模型意为求和自回归滑动平均模型(IntergratedAut少regressive MovingAverageModel),简记为ARIMA(p,d,q),p,q ...