[UCSD白板题] Changing Money
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的更多相关文章
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- [UCSD白板题] Maximize the Value of an Arithmetic Expression
Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
- [UCSD白板题] Take as Much Gold as Possible
Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...
- [UCSD白板题] Primitive Calculator
Problem Introduction You are given a primitive calculator that can perform the following three opera ...
- [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 ...
- [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 ...
- [UCSD白板题] Sorting: 3-Way Partition
Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...
- [UCSD白板题] Majority Element
Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...
随机推荐
- WCF在tcp通道下启用httpget
关于tcp通道下,启用httpget,必须启用一个http的基地址,如果要启用元数据交换,host中必须开启服务描述. //01 create host Uri tcpBaseAddress = ne ...
- 【补充版】HashMap(根据value筛选查找)
HashMap查找之根据Value查找 一般大家都知道对于HashMap而言都是通过key来进行查找.找到了key自然对应的value也就一并找到了.但是有些情况下就需要通过value来进行判断查找. ...
- mmap和shm共享内存的区别和联系
共享内存的创建 根据理论: 1. 共享内存允许两个或多个进程共享一给定的存储区,因为数据不需要来回复制,所以是最快的一种进程间通信机制.共享内存可以通过mmap()映射普通文件(特殊情况下还可以采用匿 ...
- position:absolute绝对定位解读
position:absolute绝对定位解读 摘要 用四段代码解释absolute的定位问题,进而从概念的角度切实解决html布局问题. 一.背景 常常遇到这样一些问题,很容易混淆.“浏览器屏 ...
- 应用程序缓存--manifest
应用程序缓存(Application Cache)为应用带来三个优势: 离线浏览 - 用户可在应用离线时使用它们 速度 - 已缓存资源加载得更快 减少服务器负载 - 浏览器将只从服务器下载更新过或更改 ...
- Linux默认权限的计算公式(个人理解性的笔记~)
先记下Linux下的权限可以分为 常见的 r(Read,读取):对文件,读取文件内容的权限:目录来说,具有浏览目 录的权限.权限值=4 w(Write,写入):对文件而言,具有新增.修改文件内容的权限 ...
- 帮助对@Repository注解的理解
定义(来自Martin Fowler的<企业应用架构模式>): Mediates between the domain and data mapping layers using a co ...
- C#图片压缩处理算法
原文链接:http://blog.csdn.net/szstephenzhou/article/details/38900345
- Ubuntu 远程登录服务器--ssh的安装和配置
Ubuntu的安装包居然不自带openssh服务器,所以若要使用ssh远程登录Ubuntu主机,需要首先安装ssh服务器: sudo apt-get install openssh-server 安装 ...
- 各大门户网站的css初始化代码
腾讯QQ官网 css样式初始 body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select ...