0

问题陈述:

 A system is composed of 1, 2, or 3 machines and a repairman responsible for
 maintaining these machines. Normally, the machines are running and producing 
 a product. At random points in time, the machines fail and are fixed by the
 repairman. If a second or third machine fails while the repairman is busy
 fixing the first machine, these machines will wait on the services of the 
 repairman in a first come, first served order. When repair on a machine is 
 complete, the machine will begin running again and producing a product.
 The repairman will then repair the next machine waiting. When all machines
 are running, the repairman becomes idle.

 simulate this system for a fixed period of time and calculate the fraction
 of time the machines are busy (utilization) and the fraction of time
 the repairman is busy (utilization).

现在,输入是 50 个运行时间和 50 个修复时间,然后给出计算其利用率的周期以及每个测试用例要模拟的机器数量。

样本输入:

7.0  4.5 13.0 10.5  3.0 12.0 ....
9.5  2.5  4.5 12.0  5.7  1.5 ....
20.0 1
20.0 3
0.0 0

样本输出:

       No of     Utilization
Case Machines Machine Repairman

 1       1       .525   .475
 2       3       .558   .775

案例2说明:

在此处输入图像描述

Machine Utilization   = ((7+3)+(4.5+6)+(13))/(3*20) = .558
Repairman Utilization =                   (15.5)/20 = .775

我的方法:

1)将机器加载到最小堆(称为runHeap)并给它们每个运行时间,因此下一个运行时间将是输入中50个运行时间中的一个新的,

2)计算runHeap中的最小提醒运行时间,修复队列头部的提醒修复时间或完成模拟的提醒时间之间的最小时间,并将该值称为“toGo”。

3)toGo减去runHeap中所有机器的所有提醒运行时间,toGo减去repairQueue头部的提醒修复时间,

4) 所有提醒运行时间== 0的机器,将其推入repairQueue,如果提醒修复时间== 0,则将repair Queue的头部推入runHeap,

5) 添加toGo到当前时间

6)如果当前时间<模拟时间转到步骤2,否则返回利用率。

现在,问题是这是一种好方法还是可以找出更好的方法?

4

0 回答 0