使用最大值从ATM支付一定金额的算法解决方案。更高的钞票数量 [英] An algorithmic solution for paying a certain amount money from an ATM using max. Number of higher banknotes

查看:86
本文介绍了使用最大值从ATM支付一定金额的算法解决方案。更高的钞票数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我有一个更算法而不是程序化的问题。它如下:

我们在自动取款机上有100,50,20,10,5和1(任何货币)的钞票,每种面额的具体金额(你可以检查并获得每种金额)面值)。

客户来了,想从ATM取一定数量的钱。

我需要一种算法来确定每种面额的最佳金额以支付给客户,最佳意味着使用最大数量的更高钞票。例如,如果客户想要绘制150,则最佳解决方案是1个100和1个纸币50(不是3个50)。

算法应该决定是否可以使用给定数量的纸币进行解决方案ATM和prpopse最佳解决方案。如果根本不可能,它将通知客户并提出一个解决方案,允许客户支付最少的金额,以便他们可以得到他们想要的东西。也就是说,如果他们想要绘制173并且这是不可能的,算法应该返回我不能支付你173,但再多支付2,我可以支付你175!



解决方案很紧急,非常感谢任何帮助。



提前致谢



我尝试过的事情:



我期待有人已经解决了这个或类似的问题

Hello

I have a question which is more algorithmic rather than programmatic. It follows:
We have banknotes of 100, 50, 20, 10, 5 and 1 (whatever currency) in an ATM, with specific amounts of each denomination (you can check and get the amount of each denomination).
A customer comes and wants to draw a certain amount of money from the ATM.
I need an algorithm to determine the most optimal amounts of each denomination to pay the customer, "optimal" meaning using maximum amounts of higher banknotes. E.g., if customer wants to draw 150, optimal solution is 1 note of 100 and 1 note 50 (not three 50).
The algorithm should decide if a solution is possible with the given amount of banknotes in the ATM and prpopse the optimal solution. If not possible at all, It will notify the customer and propose a solution which allows customer to pay "a min. amount of money more" so that they can get what they want. That is, if they want to draw 173 and this is not possible, the algorithm should return "I cannot pay you 173, but pay 2 more and I can pay you 175!

Solution is urgent and really really appreciate any help.

Thanks in advance

What I have tried:

I am expecting somebody has already have a soluytion to this or a similar problem

推荐答案

引用:

解决方案很紧急,非常感谢任何帮助。

Solution is urgent and really really appreciate any help.



手动获取解决方案应该不是问题。想想机械,编写用于解决问题的程序,测试它,改进。

程序就是你的算法。



我们不做你的家庭作业。

HomeWork不会在乞求别人做你的工作时测试你的技能,它会让你思考并帮助你的老师chec您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果你遇到一个特定的问题,显示你的代码并解释这个确切的问题,我们可能会帮忙。


Getting solution by hand should not be a problem. Think mechanical, write the procedure you are using to solve the problem, test it, refine.
The procedure is your algorithm.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


这个功课问题并不复杂,如果你想到它甚至一些分钟。



1)创建各种可用钞票的集合,按降序排列:

This homework problem isn't complex, if you think about it even for a few minutes.

1) Create a collection of the various banknotes that are available, order in descending value:
1000, 100, 50, 20, 10, 5, 1

2)然后循环,同时有钱分配,依次使用每个值。

2.1)整数将总和除以当前音符值 - 即要分配的音符的数量。因此,如果总和为3750,并且注释为1000,则您将有3

2.2)将剩余的总和除以注释值,并将其设置为新的总和。所以在同一个例子中,新的金额将是750.

2.3)转到下一个音符值。

2.4)如果总和现在为零,退出循环。



现在编写代码!

2) Then loop while you have money to dispense, using each value in turn.
2.1) Integer divide the sum to dispense by the current note value - that is the number of that note to dispense. so if the sum is 3750, and the note is 1000, you will have 3
2.2) Take the remainder of the sum by the note value, and set that as the new sum. So in the same example, the new sum will be 750.
2.3) Move on to the next note value.
2.4) If the sum is now zero, exit the loop.

Now write the code!


这篇关于使用最大值从ATM支付一定金额的算法解决方案。更高的钞票数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆