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. centos7 安装jdk7

    源码包准备: 首先到官网下载jdk,http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.htm ...

  2. JavaScript 学习小结

    简要的功能点: 是一种轻量级的编程语言. JavaScript 是可插入 HTML 页面的编程代码. JavaScript 插入 HTML 页面后,可由所有的现代浏览器执行. 操作 HTML 元素 d ...

  3. cinder节点部署

    其实看基础理论篇大家也可以看出来,cinder跟nova流程比较像,是这样的,nova为云主机提供了虚拟资源,cinder则是提供存储相关的资源,cinder的小伙伴叫swift,不过这个一般没人用了 ...

  4. for xml 字符串拼接

    SELECT TOP 10 B.user_gid,LEFT(StuList,LEN(StuList)-1) as hobby FROM (SELECT user_gid,( SELECT CAST(a ...

  5. WebService基本概念及原理

    一.Web Service基本概念 WebService是一种跨编程语言和跨操作系统平台的远程调用技术.Web Service也叫XML Web Service WebService是一种可以接收从I ...

  6. 第十一周PSP

    第十一周PSP   工作周期:11.24-12.1  本周PSP: C类型 C内容 S开始时间 ST结束时间 I中断时间 T净时间(分) 11月29 文档 写随笔 19:00min 19:30min ...

  7. mina IoBuffer

    mina IoBuffer 常用方法   Limit(int) 如果position>limit, position = limit,如果mark>limit, 重置mark Mark() ...

  8. python模块:base64

    base64模块是用来作base64编码解码的,在电子邮件中常见.它可以把不能作为文本显示的二进制数据编码为可显示的文本信息,编码后文本大小增加1/3.常用方法有: b64encode & b ...

  9. Spring @RequestParam @RequestBody @PathVariable 等参数绑定注解详解

    背景 昨天一个人瞎倒腾spring boot,然后遇到了一点问题,所以把这个问题总结一下. 主要讲解request 数据到handler method 参数数据的绑定,所用到的注解和什么情形下使用. ...

  10. ASI 与 AFN

    HTTP终结者.功能十分强大. 基于底层的CFNetwork框架,运行效率很高. 可惜