zoukankan      html  css  js  c++  java
  • Water Buying

    Water Buying
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Polycarp wants to cook a soup. To do it, he needs to buy exactly nn liters of water.

    There are only two types of water bottles in the nearby shop — 11 -liter bottles and 22 -liter bottles. There are infinitely many bottles of these two types in the shop.

    The bottle of the first type costs aa burles and the bottle of the second type costs bb 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 nn liters of water in the nearby shop if the bottle of the first type costs aa burles and the bottle of the second type costs bb burles.

    You also have to answer qq independent queries.

    Input

    The first line of the input contains one integer qq (1q5001≤q≤500 ) — the number of queries.

    The next nn lines contain queries. The ii -th query is given as three space-separated integers nini , aiai and bibi (1ni1012,1ai,bi10001≤ni≤1012,1≤ai,bi≤1000 ) — how many liters Polycarp needs in the ii -th query, the cost (in burles) of the bottle of the first type in the ii -th query and the cost (in burles) of the bottle of the second type in the ii -th query, respectively.

    Output

    Print qq integers. The ii -th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly nini liters of water in the nearby shop if the bottle of the first type costs aiai burles and the bottle of the second type costs bibi burles.

    Input

    4
    10 1 3
    7 3 2
    1 1000 1
    1000000000000 42 88
    Output
    10
    9
    1000
    42000000000000
     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 #define ll long long 
     5 int main(int argc, char const *argv[])
     6 {
     7     int n;
     8     cin>>n;
     9     ll k,a,b;
    10     for( int i=0; i<n; i++ ){
    11         cin>>k>>a>>b;
    12         if(a*2<=b) cout<<k*a<<endl;
    13         else{
    14             if(k%2==0) cout<<k/2*b<<endl;
    15             else cout<<k/2*b+a<<endl;
    16         }
    17     }
    18     return 0;
    19 }
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
    django migrate无效的解决方法
    KindEditor echarts
    用Django实现Video页面分类查询
    pycharm快捷键及一些常用设置
    mysql 远程访问权限
    hibernate5.2需要的最少jar文件
    Struts2.5需要的最少jar文件
    修改MySQL默认字符集编码
    Android快乐贪吃蛇游戏实战项目开发教程-06虚拟方向键(五)绘制方向键箭头
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10459409.html
Copyright © 2011-2022 走看看