首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > Python > 一个简单的方法来拆分几个人的法案

一个简单的方法来拆分几个人的法案

资 源 简 介

A scenario that motivated me to develop this python script was when I went camping with friends. Different people paid upfront for different things and not everyone uses every item. After dividing and distributing the amounts, the settlement could involve n(n-1)/2 payments among n people in the worst case. But there is a simple way to resolve this in which a person does not have to pay/collect from n-1 other people. In fact, we can first resolve the debt between any two persons. Then, we transfer all the debts/credits of either of the two to the other (like they were married and one spouse died). This way, we reduce the problem of resolving debts among n people to n-1 people. And, you know, we are done by induction. This python script does exactly this. It computes who should pay whom for how much. It also does a little checking at the end to make sure everyone pays and receives the amount they are supposed to. For n people, the script is guaranteed to generate a settlement involvin
VIP VIP
0.177295s