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;
}

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

  1. Codeforces Round #323 (Div. 2): C. GCD Table(思维题)

    题意: 给你一个长度为n的序列a[1]~a[n], 之后用这个序列生成一个n*n的矩阵,其中矩阵第i行第i列的值为a[i],第i行第j列(j!=i)的值为Gcd(a[i], a[j]),现在给你一个矩 ...

  2. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  3. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  4. Codeforces Round #590 (Div. 3) E. Special Permutations 差分 + 思维

    传送门 文章目录 题意: 思路: 题意: 思路: 直接考虑比较难想,这种公式题基本都是将部分答案看成一个整体,考虑xi,xi+1x_i,x_{i+1}xi​,xi+1​的贡献的. 假设当前的xi=x, ...

  5. Codeforces Round #726 (Div. 2) F. Figure Fixing 二分图 + 思维

    传送门 文章目录 题意: 思路 题意: 给你一张nnn个点mmm条边的图,每个点都有一个当前值aia_iai​,目标值bib_ibi​,每次可以选择一条边(i,j)(i,j)(i,j),将ai,aja ...

  6. Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 思维 + 逆序对

    传送门 文章目录 题意: 思路: 题意: 给你两个长度为nnn的串a,ba,ba,b,每次可以同时翻转a,ba,ba,b中任意一段长度为L(1≤L≤n)L(1\le L\le n)L(1≤L≤n)的子 ...

  7. Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum 思维 + 差分

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个显然的性质就是每组操作最多不会超过两次. 很容易想到一个很暴力的思路,就是枚举x∈[1,2∗k]x \in [1,2*k]x∈[1,2∗k] ...

  8. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...

  9. Codeforces Round #620 (Div. 2) E. 1-Trees and Queries 思维 + LCA

    传送门 文章目录 题意 思路: 题意 思路: 照例,先考虑不加边怎么做.由于可以经过重复的边或点,设aaa与bbb之间长度为lenlenlen,那么需要len<=klen<=klen< ...

最新文章

  1. 全球及中国不锈钢商用厨刀行业营销战略及未来发展趋势分析报告2022年版
  2. python将照片转文字_Python将图片转化成文字
  3. 组件开发之ASP.NET中集成资源文件的服务器端控件开发
  4. JsonUtils 工具类
  5. halcon模板匹配学习(二) 准备模板
  6. 深度学习目标检测网络个人总结
  7. 【Linux】shell调用Java程序main方法通过crontab定时执行
  8. 研究生开学需要准备的事宜(准研究生和保研必看)
  9. 信息安全-工控安全需求分析与安全保护工程
  10. mysql清空数据库的所有数据
  11. 山寨杂志《Nature and Science》
  12. java学生健康体检档案管理系统ssm313hf
  13. 贴片元器件焊接经验及总结
  14. 左岸读书-语不惊人死不休(95)
  15. day 46 http和html
  16. Python pywin32(一)
  17. 河南二级分销系统开发|二级分销是如何分佣的?
  18. 冒泡php_PHP实现冒泡排序
  19. python爬虫实训第六天
  20. 【最新版】友价T5交易商城源码 ,10月更新新增自助交易

热门文章

  1. 【人工智能】话说人工智能与人工神经网络的历程
  2. 服务器Linux 安装anaconda3 踩坑
  3. harris算法 matlab,Harris算法的Matlab代码
  4. 前端div的隐藏与展示控制
  5. 简单介绍展频芯片在Wince平板上的应用
  6. dpdk 内存管理 原理剖析
  7. 解决虚拟机安装64位系统“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题(一般出现在win7 旗舰版)...
  8. 在cmd下用cd命令进入不了D盘的问题
  9. 新蛋电脑报价 2007-08-26
  10. java正则匹配table_js正则匹配table tr