由两个执行者共享作业的算法

标签 algorithm queue

我在测试一些网站时遇到了以下问题:

John and Mary founded J&M publishing house and bought two old printers to equip it. Now they have their first commercial deal - to print a document consisting of N pages. It appears that printers work at different speed. One produces a page in X seconds and other does it in Y seconds. So now company founders are curious about minimum time they can spend on printing the whole document with two printers.

(取自此处http://codeabbey.com/index/task_view/two-printers)

我以为是贪心算法的问题,但据说N可以达到十亿,所以也许有一些我看不到的更简单的解决方案。我能以某种方式解决将它们按 X 和 Y 的比例划分的问题吗?

最佳答案

这似乎是一道数学题而不是算法题。作业分配为 YN/(X+Y) 页到 XXN/(X+Y) 页到 Y 。总时间为 XYN/(X+Y),这是最优的(请注意,它等效于 N/(1/X + 1/Y)。因为 YN/(X+Y) 可能不是整数,你可以只计算一些值(如果 X 向上舍入而 Y 向下舍入,反之亦然),然后取最小值。或者如您所说,您可以将两者四舍五入并将任何剩余的工作交给速度更快的机器。

关于由两个执行者共享作业的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19176589/

相关文章:

algorithm - 幻灯片算法

c - C 中不正确的插入队列

java - ORA-01031 : insufficient privileges creating JMS connection to Oracle topic

java - 在 Java 中使用 toString 和队列

algorithm - 为什么考虑 NP 而不是 P?

在二叉搜索树中查找小于给定值的所有值的算法

python - 如何查看整个队列内容和自动队列推送

python - python multiprocessing Queue 对于对象放置是否安全?

java - 如何返回 Kadane 算法中的最大子数组?

c++ - 如何让我的程序运行得更快?