-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachineDispatcherProblem.java
More file actions
51 lines (44 loc) · 1.35 KB
/
MachineDispatcherProblem.java
File metadata and controls
51 lines (44 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
public class MachineDispatcherProblem {
private static Integer workTime[] = { 35, 20, 16, 15, 13, 5, 2 };
private static int machineNumber = 3;
private static Integer min;
private static Integer max;
private static Integer minRunNumber;
private static int getMin(List<Integer> list) {
min = list.get(0);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) < min) {
min = list.get(i);
}
}
return list.indexOf(min);
}
private static int getMax(List<Integer> list) {
max = list.get(0);
for (int i = 0; i < list.size(); i++) {
if (max < list.get(i)) {
max = list.get(i);
}
}
return list.indexOf(max);
}
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < workTime.length; i++) {
list.add(workTime[i]);
}
List<Integer> listRun = new ArrayList<Integer>();
for (int i = 0; i < machineNumber; i++) {
listRun.add(list.get(i));
}
for (int i = 0; i < machineNumber; i++) {
list.remove(0);
}
for (int i = 0; i < list.size(); i++) {
minRunNumber = getMin(listRun);// 返回最小值的下标
listRun.set(minRunNumber, (list.get(i) + listRun.get(minRunNumber)));
}
System.out.println("最短的时间:" + listRun.get(getMax(listRun)));
}
}