Доказательство, что денежный алгоритм назначения Fowler корректен

Все вышеупомянутые ответы корректны, насколько я могу сказать, таким образом, я собираюсь сказать Вам что-то еще. Поскольку производство кодирует Вас, действительно должен использовать классы в java.util.concurrent. Существует очень мало, они не могут сделать для Вас в области параллелизма в Java.

15
задан joragupra 7 January 2014 в 16:45
поделиться

4 ответа

The key insight is that the total remainder is equal to the sum of the individual remainders when calculating each result[i].

Since each individual remainder is the result of rounding down, it is at most 1. There are results.length such remainders, so the total remainder is at most results.length.

EDIT: Obviously it's not a proof without some pretty symbols, so here are some...
alt text

23
ответ дан 1 December 2019 в 02:55
поделиться

Подтверждение не требуется.

Базовые суммы распределяются простым делением с округлением в меньшую сторону. So the allocated amount will always be less than or equal to the total.

Remainder contains the unallocated amount. Which will always be a whole number less than 'i'. So he simply gives each receiver 1 until the money is gone.

1
ответ дан 1 December 2019 в 02:55
поделиться

Простой

просто используйте тот факт, что

a = floor (a / b) * b + (a% b)

1
ответ дан 1 December 2019 в 02:55
поделиться

I'd say it's not correct because some curious ratio could cause a remainder greater then the number of results. Therefore I suggest results[i % results.length].amount++;.

Edit: I withdraw my answer. With longs there's no curious ratio and with floating point modulo doesn't help

0
ответ дан 1 December 2019 в 02:55
поделиться
Другие вопросы по тегам:

Похожие вопросы: