zoukankan      html  css  js  c++  java
  • Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题

    A. Optimal Currency Exchange

    Problem Description:

    Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is d rubles, and one euro costs e rubles.
    Recall that there exist the following dollar bills: 1, 2, 5, 10, 20, 50, 100, and the following euro bills — 5, 10, 20, 50, 100, 200 (note that, in this problem we do not consider the 500 euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.

    Help him — write a program that given integers n, e and d, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.

    Input
    The first line of the input contains one integer n (1≤n≤108) — the initial sum in rubles Andrew has.

    The second line of the input contains one integer d (30≤d≤100) — the price of one dollar in rubles.

    The third line of the input contains integer e (30≤e≤100) — the price of one euro in rubles.

    Output
    Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

    Input

    100
    60
    70

    Output

    40

    Input

    410
    55
    70

    Output

    5

    题意:有n个卢布,要换成美元和欧元,使手上剩余的卢克最少。一美元价值d卢布,一欧元价值e卢克.

    思路:关键:欧元的面值最小为5,则是5的倍数,美元最小面值为1。

    写法:特判+枚举。

    AC代码:

    //欧元的面值最小为5,其实的都少5的倍数,美元最小面值为1。
    /*
    1 dollar---> d rubles
    1 euro ----> e rubles
     
    dollar  1 2 5 10 20 50 100
    euro     5 10 20 50 100 200
     
    */
    #include<bits/stdc++.h>
     
    using namespace std;
     
    #define int long long
     
    signed main(){
        int n,d,e;
        cin>>n>>d>>e;
        int ans=n;
        int x1=n/e;
        if(x1<5){
            printf("%lld
    ",n-(n/d)*d);return 0;
        }else{
            int t1=n/(e*5);
            for(int i=0;i<=t1;i++){
                int temp=n;
                temp=temp-e*i*5-((n-e*i*5)/d)*d;
                //int sum2=temp-(temp/d)*d;
                ans=min(ans,temp);
            }
            printf("%lld
    ",ans);
            
        }
        return 0;
    }
  • 相关阅读:
    [py]str list切片-去除字符串首尾空格-递归思想
    [py]python面向对象的str getattr特殊方法
    [py]python多态-动态语言的鸭子类型
    [py]py2自带Queue模块实现了3类队列
    【Unity技巧】制作一个简单的NPC
    java7 新特性 总结版
    【游戏周边】Unity,UDK,Unreal Engine4或者CryENGINE——我应该选择哪一个游戏引擎
    【Unity Shaders】Transparency —— 使用alpha通道创建透明效果
    记录最近的几个bug
    理解WebKit和Chromium: 调试Android系统上的Chromium
  • 原文地址:https://www.cnblogs.com/pengge666/p/11474409.html
Copyright © 2011-2022 走看看