Souvenir

 Accepts: 901
 Submissions: 2743
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 262144/262144 K (Java/Others)
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.
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h> using namespace std; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
__int64 sum = 0;
int n,m,p,q;
scanf("%d%d%d%d",&n,&m,&p,&q);
if(p*m<=q)
{
printf("%d\n",p*n);
}
else
{
sum = (n/m)*q;
n = n%m;
if(n*p<q)
{
printf("%I64d\n",sum+n*p);
}
else
{
printf("%I64d\n",sum+q);
}
}
}
return 0;
}

HDU 5310 Souvenir的更多相关文章

  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 (水)

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

  3. hdu 5310(贪心)

    题意:要买n个纪念品,单价p元,有团购价 m个q元,问怎样买钱最少 这个是BC周年庆第一题,水题昂,小学数学题,就是看n个纪念品单买.总体买团购然后零头买单价的.全部买团购价的多买也无所谓的,然后直接 ...

  4. (01背包)Buy the souvenirs (hdu 2126)

    http://acm.hdu.edu.cn/showproblem.php?pid=2126 Buy the souvenirs Time Limit: 10000/1000 MS (Java/Oth ...

  5. hdu 2126 Buy the souvenirs 二维01背包方案总数

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. HDU 2126 01背包(求方案数)

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. hdu 2126 Buy the souvenirs(记录总方案数的01背包)

    Buy the souvenirs Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. How-to-quick-getting-started-for-Frontend

    一转眼已一年多不专注前端方面的开发工作,这一年前端方面的技术又是新天地,偶然接到内部团队邀请我给他们做一个前端的讲座,希望能帮助他们快速.且深刻了解前端这个行业以及行业内的知识,这可真有点让我为难,由 ...

  2. ANY和ALL

    8.在WHERE中使用ANY和ALL条件   字段 >ANY(值1,值2,值3...):字段值大于集合任何一个       值就算满足条件.     字段 >ALL(值1,值2,值3... ...

  3. jQuery判断浏览器类型和版本

    jquery 判断浏览器类型 例:   if($.browser.msie) { alert("这是一个IE浏览器"); }else if($.browser.opera) { a ...

  4. ZOJ 3556

    终于做出来了,激动.... 这道题隐藏得深啊,但若推导下来,就变简单了. 首先,一个集合的子集的个数为2^n=s.注意了,题目求的是有序集合组,并且每个集合是可以重复使用的,怎么办呢?这就要想到多重集 ...

  5. poj 3311 Hie with the Pie (TSP问题)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 ...

  6. MyBatis数据持久化(三)增删改查

    上篇文章中我们使用mybatis成功建立数据库会话,并从表中查询出相应的数据,本文在此基础上介绍MyBatis另外几种操作,即插入.修改.删除记录. 1.修改User.xml文件,增加几条sql语句: ...

  7. 新疆大学OJ(ACM) 1047: string 字符串排序

    1047: string 时间限制: 1 Sec  内存限制: 128 MB 题目描述 有n个字符串字符串n<=50000,把所有字符串串起来,得到一个字典序最小的字符串. 输入 输入第一行是一 ...

  8. solarwinds之数据库

      1.              Orion配置向导     2.              连接数据库     3.              创建一个新的数据库     4.           ...

  9. linux下mysqldump简单命令导出数据库和表

    进入mysql的bin目录执行: 导出单个表: mysqldump -uroot -ppassword --database dbname --tables users > /home/root ...

  10. luogu P3414 SAC#1 - 组合数(组合数学)

    题意 求sigma(C(n,i))其中C是组合数(即C(n,i)表示n个物品无顺序选取i个的方案数),i取从0到n所有偶数. 由于答案可能很大,请输出答案对6662333的余数. (n<=101 ...