Problem Introduction

In this problem,you will design an algorithm for changing money optimally.

Problem Description

Task.The goal in this problem is to find the minimum number of coins needed to change the input value(an integer) into coins with denominations 1,5,and 10.

Input Format.The input consists of a single integer \(m\).

Constraints.\(1 \leq m \leq 10^3\).

Output Format.Output the minimum number of coins with denominations 1,5,10 that changes m.

Sample 1.
Input:

2

Output:

2

Explanation:
2=1+1

Sample 2.
Input:

28

Output:

6

Explanation:
28=10+10+5+1+1+1

Solution

# Uses python3
import sys

def get_change(n):
    count = 0
    coins = [10, 5, 1]
    for coin in coins:
        if coin <= n:
            count += n // coin
            n %= coin
    return count

if __name__ == '__main__':
    n = int(sys.stdin.read())
    print(get_change(n))

[UCSD白板题] Changing Money的更多相关文章

  1. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  2. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  3. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  4. [UCSD白板题] Take as Much Gold as Possible

    Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...

  5. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  6. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  7. [UCSD白板题] Number of Inversions

    Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...

  8. [UCSD白板题] Sorting: 3-Way Partition

    Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...

  9. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

随机推荐

  1. CocosCreator反射在Android中的使用

    CocosCreator反射在Android中的使用 新建一个CocosCreator项目,然后点击构建 构建完成之后,即可用AndroidStudio打开构建的项目 使用AndroidStudio打 ...

  2. 纯js异步无刷新请求(只支持IE)

    纯js异步无刷新请求 下载地址:http://pan.baidu.com/s/1slakL1F 所以因为非IE浏览器都禁止跨域请求,所以以只支持IE. <HTML> <!-- 乱码( ...

  3. IE11部分图片无法显示的兼容办法

    问题描述:写的网页在浏览器中测试兼容问题,FF,Chrome,Edge都完美兼容(包括Edge中的仿真),但是在IE11中却无法显示部分图片,并且报:DOM7009: 无法解码 URL 处的图像 错误 ...

  4. ios -网络加载json和本地加载json

    1网络加载json的时候,要在模型的实现文件里写: - (void)setValue:(id)value forKey:(NSString *)key { } 2本地加载json的时候,要在模型的实现 ...

  5. VMware Workstation+Linux+Xshell+Xftp+MySQL+SQLyog 配置

    这些天在搞这些个东西做项目,配置较繁,这里记下安装过程中的要点. 1.VMware Workstation 主要是 NAT 方式联网的问题,详述如下,来自网络. NAT 配置那里注意网关,虚拟机中网关 ...

  6. selenium第二课(脚本录制seleniumIDE的使用)

    一.Selenium也具有录制功能,可以web中回放,录制的脚本可以转换为java.python.ruby.php等多种脚本语言.seleniumIDE是Firefox的一个插件,依附于Firefox ...

  7. 关于dp dip dpi px

    在Android开发中,屏幕适配是一件非常让人头疼的事情.有时候在这个机型上调试的漂漂亮亮的UI界面,换一部手机就丑的不忍直视.但为了我们软件更好的用户体验,我们必须适应Android市场上形形色色的 ...

  8. Visual Studio 2010 插件之Resharper

    这一系列不是对每个功能的中文帮助,而是我对开发中可能涉及的功能需求,利用Resharper来完成.有些是Visual Studio有的,但是做的不好,有些是没有而Resharper发明的.总的目的都只 ...

  9. eclipse中的代码提示功能

    Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后"window"→"Preferences" 2. 选择"java" ...

  10. git更换仓库地址

    1.  从原始地址 clone 一份不包含 work copy的仓库: git clone --bare bitbucket_project_address 2. 在os china上创建同名项目. ...