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. [Apple开发者帐户帮助]三、创建证书(6)创建创建VoIP服务证书

    VoIP:基于IP的语音传输(英语:Voice over Internet Protocol,缩写为VoIP)是一种语音通话技术,经由网际协议(IP)来达成语音通话与多媒体会议,也就是经由互联网来进行 ...

  2. windows10+arch linux双系统 uefi启动

    安装前的准备Archlinux 安装ISO镜像,下载:http://mirrors.163.com/archlinux/iso/2013.05.01/U盘一个,最好1G以上,格式化成FAT32.把下载 ...

  3. C#格式化年月日截取

     //if (bm.Name == "DateYear") //年                 //{                 //    bm.Select();   ...

  4. EditPlus 4:设置字体

    打开软件上面菜单栏点击Tools,在此下拉栏点击Configure User Tools,在弹出的设置框在左边框框中找到General->Fonts,显示的左边框即为字体框,具体如图:

  5. [编码]ASCII、GBK、Unicode(万国码) 和 UTF-8

    American ASCII编码 (American Standard Code for Information Interchange,美国信息互换标准代码)  China    gbk编码     ...

  6. Verification之PSL之use

    1 Where can PSL be used? • Documentation – Requirements – RTL Designs • Controllers – Memories, FIFO ...

  7. 腾讯模板引擎template

    template.js是一款JavaScript模板引擎,用来渲染页面的. 原理:提前将Html代码放进编写模板  script id="tpl" type="text/ ...

  8. element-ui按需引入

    { "name": "vue-test2", "description": "A Vue.js project", &q ...

  9. tomcat映射java目录 sever.xml

    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />        --> & ...

  10. Spring实战(中文4,5版) PDF含源码

    Spring实战 读者评价 看了一半后在做评论,物流速度挺快,正版行货,只是运输过程有点印记,但是想必大家和你关注内容,spring 4必之3更加关注的是使用注解做开发,对于初学者还是很有用,但是不排 ...