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

http://acm.hdu.edu.cn/showproblem.php?pid=5310

题目大意:要买n个纪念品,可以单个买p元每个,可以成套买q元一套,每套有m个,求最少花费

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define N 110

using namespace std;

int main()
{
    int t, sum, n, m, p, q, a, b;
    scanf("%d", &t);
    while(t--)
    {
        sum = 0;
        scanf("%d%d%d%d", &n, &m, &p, &q);
        a = n / m;
        b = n % m;
        if((n - b) * p > a * q)
            sum += a * q;
        else
            sum += (n - b) * p;
        if(b * p > q)
            sum += q;
        else
            sum += b * p;
        printf("%d\n", sum);
    }
    return 0;
}
时间: 2024-10-11 11:03:52

hdu 5310 Souvenir(BestCoder 1st Anniversary ($))的相关文章

hdu 5310 Souvenir (简单题)

这是一道稍微仔细想想就可以做出来的简单题,而我wa了两次,这也是把它写上来的原因,只是因为我没有认真想,还是不够仔细啊,还是很马虎啊,不能慌张,得仔细读题,慢慢想题. 思路: 一共只有几种情况:1全部用单价p买:2全部用套装q买:3先用套装买,剩下的用单价p买 注:不必判断先用单价p再用套装(如果先用p的话就证明单价比套装更划算(买相同数量所需要的话费)) 贴代码: #include<stdio.h> #include<stdlib.h> #include<string.h&

HDU 5124 lines(BestCoder Round #20)

Problem Description: John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input: The first line contains a single integer T(1≤T≤100)(the data for 

HDU 5167 Fibonacci(BestCoder Round #28)

Problem Description: Following is the recursive definition of Fibonacci sequence: Fi=???01Fi−1+Fi−2i = 0i = 1i > 1 Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence. Input: There is a number T 

HDU 5101 Select(BestCoder Round #17)

Problem Description: One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting game. He wants to take part in the game. But as we all know, you can't get good result without teammates.So, he needs to select two classmates as

HDU 4932 Miaomiao&#39;s Geometry(BestCoder Round #4)

Problem Description: There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length. There are 2 limits: 1.A point is convered if there is a segments T , the point is the left end or the right end of T.2.The le

hdu 4909 String (map + 状压)

题目大意: 给定一个可能含'?'的字符串.然后问这个字符串有多少个子串是含有所有的字符都只出现两次. 其中'?' 可以被替换成任意字符,也可以被remove... 思路分析: 这是bestcoder的round #3的第三题. 这道题的做法和 4908 的做法差不多. 我们把 '?' 左右两边的状态分别处理出来. 然后用map 计数.然后枚举左边的状态.同时枚举? 对应的字符. 然后去寻找右边对应的状态,此时 ans 就可以加上答案. 注意的是要考虑到以 ? 结尾的情况.所以在 ? 的状态要和上

HDU 1541 Stars (树状数组)

Problem Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given

hdu 1175 连连看(模拟循环队列)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18149    Accepted Submission(s): 4741 Problem Description "连连看"相信很多人都玩过.没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子.如果某两个相同的棋子,可以通过一条线连起来(这条

HDU 1853Cyclic Tour(网络流之最小费用流)

题目地址:HDU1853 费用流果然好神奇..还可以用来判断环...如果每个点都是环的一部分而且每个点只能用到一次的话,那每个点的初度入度都是1,这就可以利用网络流来解决,只要拆点令其流量为1,就限制了每个点只能用一次,每次左边的连到右边的,就相当于左边点的一次初度和右边的点的一次入度,很容易想象出来.最后只要判断总流量是否为n即可,因为如果总流量为n的话,说明每个点都出了一次度,每个点都入了一次度,而且由于拆点的流量限制,充分说明了每个点的初度入度都是1.进而说明了每个点都在环里.然后输出最后