[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 ...
随机推荐
- CSS overflow 属性
值 描述 visible 默认值.内容不会被修剪,会呈现在元素框之外. hidden 内容会被修剪,并且其余内容是不可见的. scroll 内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容. ...
- npm install 出现UNABLE_TO_GET_ISSUER_CERT_LOCALLY
解决方式 As a workaround you can turn ssl checking off in your .npmrc 执行 npm config set strict-ssl false ...
- [MVC] DIV 布局
[MVC] DIV 布局 <style> .top { background-color: red; height: 50px; top: 0px; position: absolute; ...
- HashMap的两种实现方式
本文主要简要分析了Java中和Redis中HashMap的实现,并且对比了两者的异同 1.Java的实现 下图表示了Java中一个HashMap的主要实现方式 因为大家对于Java中HashMap的实 ...
- ajax实现jsonp跨域接口
HTML页面代码: <script type="text/javascript"> function UrlSearch(){ var name,value; var ...
- 【POJ2778】DNA Sequence(AC自动机,DP)
题意: 生物课上我们学到,DNA序列中只有A, C, T和G四种片段. 经科学发现,DNA序列中,包含某些片段会产生不好的基因,如片段"ATC"是不好片段,则"AGATC ...
- js event 事件冒泡和事件捕获详细介绍
. 参考: http://www.jb51.net/article/42492.htm 图: 假设一个元素div,它有一个下级元素p.<div> <p>元素</p> ...
- HDMI学习
市面上大多4K显示器都配备了HDMI 1.4接口,仅能实现30Hz的刷新率,不足以带来流畅的显示效果, 酱紫情况,就算是搭配了HDMI 2.0高清线也是无法发挥其作用.只有更先进的HDMI 2.0标准 ...
- iOS打包ipa包
创建证书之类这里就不说了,毕竟我也没有弄过. 我是团队开发,直接给我的p12文件,去开发者中心下载provision并且是distribute的就可以了. 1>.Xcode打包: 注意两个地方都 ...
- jQuery检查某个元素在页面上是否存在
用jQuery检查某个元素在网页上是否存在时,应该根据获取元素的长度来判断,代码如下: if($("#tt").length > 0) { //元素存在时执行的代码 } 具体 ...