問題文:
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) runHeap 内のすべてのマシンのすべてのリマインド実行時間を toGo で減算し、repairQueue のヘッドのリマインド修復時間を toGo で減算します。
4) リマインダー実行時間 == 0 のすべてのマシンは、それを repairQueue にプッシュします。リマインド リペア時間 == 0 の場合、リペア キューの先頭は、それを runHeap にプッシュします。
5) toGo を現在時刻に追加
6) 現在の時間 < シミュレーション時間の場合はステップ 2 に進み、そうでない場合は使用率を返します。
さて、質問はそれが良いアプローチですか、それともより良いアプローチを見つけることができますか??