Codeforces Round #540 (Div. 3)--A. Water Buying(简单思维题-有点坑)

A. Water Buying

题目链接http://codeforces.com/problemset/problem/1118/A

time limit per test:1 second

memory limit per test:256 megabytes

Polycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water.
There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely many bottles of these two types in the shop.

The bottle of the first type costs a burles and the bottle of the second type costs b burles correspondingly.

Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly n liters of water in the nearby shop if the bottle of the first type costs a burles and the bottle of the second type costs b burles.
Input

The first line of the input contains one integer q(1<=q<=500)— the number of queries.

The next n lines contain queries. The i-th query is given as three space-separated integers ni, ai,bi(1<=ni<=1012,1<=ai,bi<=1000)— how many liters Polycarp needs in the i-th query, the cost (in burles) of the bottle of the first type in the i-th query and the cost (in burles) of the bottle of the second type in the i-th query, respectively.

Output

Print q integers. The i-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly ni liters of water in the nearby shop if the bottle of the first type costs ai burles and the bottle of the second type costs biburles.

Example

Input

4
10 1 3
7 3 2
1 1000 1
1000000000000 42 88

Output

10
9
1000
42000000000000


题目大意:你需要买N升的水,现有a类a元/1升,b类b元/升。问恰好装满N需要的最少钱。
emmm。。。刚开始我还以为是01背包,但1012让我放弃了原来的想法。
想一想,这里只有两个数据,我们又想到所有大于0的数都可以由n个2和1个1构成。那么我们的思路一下子就出来了。比较一下a的单价和b的单价如果a的单价小,我们就直接返回答案N*a。否则我们需要的钱就是(n/2)*b+a;
以下是详细代码:

#include <cstdio>
#define ll long long
int main()
{
	ll t,n,a,b;
	scanf ("%lld",&t);
	while (t--){
		scanf ("%lld%lld%lld",&n,&a,&b);
		double x=b/2;
		long long mon;
		if (x+1e-10<(double)a) {
			if (n&1) mon=(n/2)*b+a;
			else mon=(n/2)*b;
		}
		else mon=n*a;
		printf ("%lld\n",mon);
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值