BestCoder 1st Anniversary
Souvenir
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.
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).
For each test case, output the minimum cost needed.
2
1 2 2 1
1 2 3 4
1
3HintFor 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.
BestCoder周年纪念赛,趁着还没结束,来一发水题题解(其实是卡题了(/ □ \)囧)
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,m,p,q,T,flag;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&p,&q);
if(n<=m)
flag = min(p*n,q);
else
{
if(p<=q/m)
flag = n*p;
else {
int x = n/m*q;
int y = (n-n/m*m)*p;
int z = (n/m+1)*q;
flag = min(x+y,z);
}
}
printf("%d\n",flag);
} return 0;
}
BestCoder 1st Anniversary的更多相关文章
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ...
- BestCoder 1st Anniversary($) 1003 Sequence
题目传送门 /* 官方题解: 这个题看上去是一个贪心, 但是这个贪心显然是错的. 事实上这道题目很简单, 先判断1个是否可以, 然后判断2个是否可以. 之后找到最小的k(k>2), 使得(m-k ...
- hdu 5311 Hidden String (BestCoder 1st Anniversary ($))(深搜)
http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others) ...
- BestCoder 1st Anniversary ——HDU5312(数学推导)
Today, Soda has learned a sequence whose n-th (n≥1) item is 3n(n−1)+1. Now he wants to know if an in ...
- BestCoder 1st Anniversary B.Hidden String DFS
B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...
- BestCoder 1st Anniversary ($) 1002.Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...
- BestCoder 1st Anniversary 1004 Bipartite Graph 【二分图 + bfs + 良好的逻辑思维 】
题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=610&pid=1004 问题描述 Soda有一个$ ...
- hdu 5310 Souvenir(BestCoder 1st Anniversary ($))
http://acm.hdu.edu.cn/showproblem.php?pid=5310 题目大意:要买n个纪念品,可以单个买p元每个,可以成套买q元一套,每套有m个,求最少花费 #include ...
- 【BestCoder 1st Anniversary】
AB题都是签到题.... C 题意: 有一串数列,An=3*n*(n-1)+1 然后要从A数列中选取尽量少个数(可重复),使得Sum(An)=m 题解: 贪心地想,能拿大就拿大很明显就是错的...[哪 ...
随机推荐
- Github Https方式push错误”Empty reply from server”
1 2 3 4 5 6 7 8 9 10 2014-11-19 20:41:30.130 GitHub for Mac Login[2595:326257] AskPass ...
- Fiddle的应用
在Composer中输入测试的网址: 可能会发生一下情况,这意味着需要在左侧面板中选择一项,来看回应: 选择一个请求后,选择TextView,看原生的回应(Response)内容
- 单个ViewController支持横屏,其他全竖屏方法-b
如果项目中用了navigationViewController, 那么就应该新建一个uinavigationViewController的子类,然后在这个类里面写上下面的代码,在使用的时候就用自定义的 ...
- Unity3D中的Coroutine详解
Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这样的代码. 疑问: yield是什么? Coroutine是什么? unity的coroutin ...
- js 实现 aop
Aop又叫面向切面编程,用过spring的同学肯定对它非常熟悉,而在js中,AOP是一个被严重忽视的技术点,这篇就通过下面这几个小例子,来说说AOP在js中的妙用. 1, 防止window.onloa ...
- Swordfish
zoj1203:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1203 题意:给定平面上N个城市的位置,计算连接这N个城市所 ...
- Js中的window.parent ,window.top,window.self详解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- Strust2的json插件
以下这段摘自网上: Json是一种轻量级的数据交换格式,JSon插件提供了一种名为json的ActionResultType .一旦为Action指定了该结果处理类型,JSON插件就会自动将Actio ...
- ZKW费用流修正
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #inc ...
- 如何在Sqlserver2000查询分析器中,,在一个库中调用另一个数据库中的数据表
同一服務器 use aa select * from pubs.dbo.jobs 不同服務器 select * from openrowset('sqloledb','IP地址';'sa';'密碼', ...