Algorithm for sharing jobs by two executors

随声附和 提交于 2019-12-04 21:47:46

This seems to be a math question rather than algorithm question. The job distribution would be YN/(X+Y) pages to X, XN/(X+Y) pages to Y. Total time would be XYN/(X+Y) which is optimal (note that it is equivalent to N/(1/X + 1/Y). Since YN/(X+Y) might not be integer, you can just calculate a few values (if X is rounded up and Y is rounded down, and vice versa) , then take the minimum. Or as you said, you can round down both and give any remaining jobs to the faster machine.

for i in range(int(input())):
    x,y,n = list(map(float, input().split()))
    x_1 = int(y*n / (x+y))
    y_1 = int(x*n/ (x+y))
    n = n - (x_1 + y_1)
    x_ans = int(max( (x_1 + n)* x, y_1 * y))
    y_ans = int(max( x_1 * x, (y_1 + n) * y))

    print(min(x_ans,y_ans),end=' ')
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!