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. java实现简单的验证码(待增强)

    package com.xxx; import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;import java.a ...

  2. [Docker] docker 基础学习笔记4(共6篇)

    离线安装nginx   apache 如何启动war包   linux 离线升级内核   nginx和Apache的使用   nginx 的负载均衡配置 是如此的简单,比weblogic的要简单100 ...

  3. [转]保护眼睛的Windows和IE、Firefox、谷歌等浏览器颜色设置

    保护眼睛的Windows和IE.Firefox.谷歌等浏览器颜色设置  长时间在电脑前工作,窗口和网页上的白色十分刺眼,眼睛很容易疲劳,也容易引起头痛,其实我们可以通过设置Windows窗口和软件的颜 ...

  4. tesseract配置过程

    tesseract配置过程: 1. 为了避免配置环境变量,可以先下载一个 tesseract-ocr-setup-3.02.02.exe(tesseract配置文件夹里有),然后安装(假设安装目录为D ...

  5. Iterator(迭代器)-对象行为型模式

    1.意图 提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露该对象的内部表示. 2.别名 Cursor-游标. 3.动机 一个聚合对象,应该提供一种方法来让别人可以访问它的元素,而又不需暴露它的 ...

  6. java_jdk_JDK版本切换批处理脚本

    我们平时在window上做开发的时候,可能需要同时开发两个甚至多个项目,有时不同的项目对JDK的版本要求有区别,这时候我们可能会在一台电脑上安装多个版本的JDK,如下图所示:

  7. 启动Tomcat时报 Expected stackmap frame at this location.(JDK1.7编译)

    从svn上下的项目,部署到tomcat 7.0.19 上, 并且配置的是jdk7.  启动时出现以下问题. Location: com/genlot/loms/service/SysPermissio ...

  8. git资料图

  9. 在CMMI推广过程中EPG常犯的错误(转)

    本文转自: http://developer.51cto.com/art/200807/86953.htm 仅用于个人收藏,学习.如有转载,请联系原作者. ---------------------- ...

  10. Linux系统编程温故知新系列 --- 01

    1.大端法与小端法 大端法:按照从最高有效字节到最低有效字节的顺序存储,称为大端法 小端法:按照从最低有效字节到最高有效字节的顺序存储,称为小端法 网际协议使用大端字节序来传送TCP分节中的多字节整数 ...