算法分享/结算费用的一组 [英] Algorithm to share/settle expenses among a group

查看:133
本文介绍了算法分享/结算费用的一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待着一个算法以下问题。

I am looking forward for an algorithm for the below problem.

问题:将有一组人谁欠对方一些钱或没有。现在,我需要一个算法(最好和纯)解决费用包括其中。

Problem: There will be a set of people who owe each other some money or none. Now, I need an algorithm (the best and neat) to settle expense among this group.

Person AmtSpent
------ ---------
A       400  
B      1000  
C       100  
Total  1500

现在,费用每人为三分之一千五百= 500含义B至给一个100 B至给出了C 400。我知道,我就可以开始用最少的花费金额和工作着。

Now, expense per person is 1500/3 = 500. Meaning B to give A 100. B to give C 400. I know, I can start with the least spent amount and work forward.

有人能指出我最好的一个,如果你有。

Can some one point me the best one if you have.

在此先感谢。

综上所述, 1.查找每头总费用和费用。
2.找到每个欠或已发行额(-VE表示优秀)。
3.开始用最少+已经量。分配给-ve量。
4.请重复步骤3,直到用完-ve量。
秒。移动到下一个更大+已经数。不断重复3及4,直到有+已经号码。

To sum up, 1. Find the total expense, and expense per head.
2. Find the amount each owe or outstanding (-ve denote outstanding).
3. Start with the least +ve amount. Allocate it to the -ve amount.
4. Keep repeating step 3, until you run out of -ve amount.
s. Move to next bigger +ve number. Keep repeating 3 & 4 until there are +ve numbers.

或者有什么更好的办法呢?我只是好奇。 :)

Or is there any better way to do? I am just curious. :)

推荐答案

您已经将其形容了。由人民共享的费用(500)号码总结所有的费用(在你的案件1500),鸿沟。对于每一个人来说,扣除那人从个股的贡献(适用于某甲,扣除400 500)。其结果是,人欠到中央池净。如果该数字为负,任何人,池中央欠的人。

You have described it already. Sum all the expenses (1500 in your case), divide by number of people sharing the expense (500). For each individual, deduct the contributions that person made from the individual share (for person A, deduct 400 from 500). The result is the net that person "owes" to the central pool. If the number is negative for any person, the central pool "owes" the person.

由于您已经描述的解决方案,我不知道你是问。 也许你正在试图解决这个问题,而不池中央,在银行?

Because you have already described the solution, I don't know what you are asking. Maybe you are trying to resolve the problem without the central pool, the "bank"?

我也不知道你的意思是开始用最少的花费金额和工作向前推进。

I also don't know what you mean by "start with the least spent amount and work forward."

这篇关于算法分享/结算费用的一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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