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. Python 44 前端概述 、三剑客 、常用标签与分类

    1.前端三剑客是哪三位?文件的后缀内容?在前端开发中的功能是什么? HTML:   .htm .html   内容 CSS:   .css   效果 JS:   .js   行为 2.简述三剑客的主要 ...

  2. JVM内存模型和GC垃圾回收

    JVM 内存区域 1.程序计数器 这是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器,指的是上次代码被执行的地方,线程私有. 2.Java 虚拟机栈 它是 Java方法执行的 ...

  3. Cracking the Coding Interview 10.7

    Design an algorithm to find the kth number such that the only prime factors are 3,5 and 7 方法一: a[i]= ...

  4. GitHub上fork别人打代码后如何保持和原作者同步的更新

    1.进入你的GitHub发起Pull  request 2.选择compare across  forks 3.反向操作.base fork改为自己的,head fork改为原作者的 4.点击 cre ...

  5. 3B课程笔记分享_StudyJams_2017

    昨晚才发现 Study Jams China的官方论坛也支持MarkDown,所以直接发在了那上面.http://www.studyjamscn.com/thread-21807-1-1.html

  6. DB2数据常用指令

    ************************************************************** 这个只是个人平时总结,如果有更好的欢迎告诉我,一起学习一起成长 ***** ...

  7. asp.net mvc学习入门

    MVC是什么? M: Model就是我们获取的网页需要的数据 V: View就是我们的aspx页面,注意这是一个不包含后台代码文件的aspx页面.(其实带有.asp.cs文件也不会有编译错误,但是这样 ...

  8. centos6.5 安装redis自动启动

    1.安装需要的支持环境 在安装Redis之前首要先做的是安装Unix的 Tcl工具 ,如果不安装的话后期将无法对Redis进行测试.在后期执行make test的时候返回如下错误信息: You nee ...

  9. jquery获取当前时间并且格式化

    Date.prototype.Format = function (fmt) {      var o = {          "M+": this.getMonth() + 1 ...

  10. 【剑指Offer】9、变态跳台阶

      题目描述:   一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法.   解题思路:   当只有一级台阶时,f(1)=1:当有两级台阶时, ...