图a
return lst
图b
freeh=-1;freelst=[]
while i<n:
if allot[i]==0xff:
j=i+1
while ①
j+=1
freelst.append([i,j-i,-1])
if freeh==-1:
freeh=cur=len(freelst)-1
else:
freelst[cur][2]=len(freelst)-1
②
else:
return freeh,freelst
for i in range(freelst[p][1]):
print(③
p=freelst[p][2]
图a
图b
'初始化各城市名胜值,并在List l中输出,代码略。
'从Text 1中读取航线信息,存储到map数组,isBack数组,代码略。
'map(1)-map(10)分别表示1号城市到1~10号城市的航线情况。
'map(11)~map(20)分别表示2号城市到1~10号城市的航线情况,以此类推。
'16题图a中的航线信息在map数组中的表示如第16题图b所示。T表示值为True,空表示值为False。
'可知map(2)、map(3)、map(4)、map(15)……等元素的值为True
End Sub
Private Sub Command1_Click()
Dim endCity(1To n)As Integer
Dim prev(1 To n)As Integer
Dim tour As String
Dim cnt As Integer
For i=2 To n '计算每个城市的路线名胜值
For j=1Toi-1
tmp=
If map(tmp)And pathPoints(i)<pathPoints(j)+cityPoint(i)Then
pathPoints(i)=pathPoints(j)+cityPoint(i)
prev(i)=j
End If
Next j
Next i
cnt=1:maxPoints=0 '找出符合条件的路线
For i=1To n
If isBack(i)And pathPoints(i)>maxPoints Then
maxPoints=pathPoints(i)
cnt=1
Elself isBack(i)And pathPoints(i)=maxPoints Then
cnt=cnt+1
End If
Next i
ct=0:flag=False '输出路线
maxPoints=maxPoints +cityPoint(1)
For i=1 To cnt
city=endCity(i)
tour=""
Do While city<>0
tour=Str(city)+"→"+tour
ct=city
Loop
tour="路线"+CStr(i)+":"+tour+"11,路线名胜值:"+CStr(maxPoints)
If ct=1Then List2.Addltem tour:flag=True
Next i
If Not flag Then List2.Addltem"无符合要求的线路”
End Sub
进程 | 到达时间 | 运行时长 | 优先级 |
A | 0 | 7 | 1 |
B | 2 | 4 | 2 |
C | 4 | 1 | 3 |
D | 5 | 4 | 2 |
表1
def insert(p, remain):
data[p][2]=remain #更新进程剩余的运行时间
lvl=data[p][3] #获取p进程的优先级
if queinfo[lvl][0]=-1:
queinfo[lvl][0]=p
if queinfo[lvl][1]!=-1:
data[queinfo[lvl][1]][-1]=p
queinfo[lvl][1]=p
m=int(input('设置优先级的数量m:'))
# 输入列表data存储进程,data中的节点包含信息有[名称,到达时间,运行时长,优先级],
代码略
# 进程已经按到达时间升序排序
#例如:data=[['A',0,7,1],['B',2,4,2],['C',4,1,3],['D',5,4,2]]
for i in range(len(data)):
data[i].append(-1)
queinfo=[[-1, -1] for i in range(m+1)]
insert(0, data[0][2]) #将第1个进程加入队列
time=data[0][1] 0
cnt=1 #所有队列内等待的进程总数
idx=1
lvl=m
while cnt>0:
if queinfo[lvl][0]!=-1:
cur=queinfo[lvl][0]
queinfo[lvl][0]=data[queinfo[lvl][0]][-1]
cnt-=1
while idx < len(data) and time+data[cur][2]>=data[idx][1]:
if lvl >= data[idx][3] or time+data[cur][2]==data[idx][1]:
insert(idx, data[idx][2])
cnt+=1
idx +=1
elif time+data[cur][2]> data[idx][1]:
insert(idx, data[idx][2]) #抢占的进程也先入队
cnt +=1
inset(cur,
cnt +=1
time=data[idx][1]
lvl =data[idx][3]
idx+=1
flag =True
break
if flag==False:
time = time+data[cur][2]
print("时刻", time, ":进程", data[cur][0], "完成")
lvl = m
if
insert (idx, data[idx][2])
cnt +=1
time=data[idx][1]
idx += 1
else:
lvl-=1
if lvl==0:
lvl=m
序号 | 品种 | 送达时间 | 批次 | 重量(千克) | 序号 | 品种 | 送达时间 | 批次 | 重量(千克) | |
1 | 2 | 8:35 | 1 | 6 | 1 | 0 | 8:30 | 2 | 3 | |
2 | 1 | 8:50 | 1 | 8 | 2 | 2 | 8:35 | 1 | 6 | |
3 | 0 | 9:10 | 1 | 2 | 3 | 0 | 8:40 | 3 | 4 | |
4 | 0 | 9:15 | 1 | 4 | 4 | 1 | 8:50 | 1 | 8 | |
5 | 0 | 9:10 | 1 | 2 | ||||||
序号 | 品种 | 送达时间 | 批次 | 重量(千克) | 6 | 0 | 9:15 | 1 | 4 | |
1 | 0 | 8:30 | 2 | 3 | 图a-2 | |||||
序号 | 品种 | 送达时间 | 批次 | 重量(千克) | ||||||
1 | 0 | 8:40 | 3 | 4 |
图a-1
m=10 data=[1,0,’8:30’,2,3],[2,2,’8:35’,1,6],[3,0,’8:40’,3,4], [4,1,’8:50’,1,8],[5,0,’9:10’,1,2],[6,0,’9:15’,1,4] 第1个包裹中品种为0,各物品的序号依次是:3,1,5, 第2个包裹中品种为0,各物品的序号依次是:6, 第3个包裹中品种为1,各物品的序号依次是:4, 第4个包裹中品种为2,各物品的序号依次是:2, |
图b
for i in range(n-1):
for j in range(n-1,i,-1):
if 1st[j][2]<1st[j-1][2]:
1st[j],1st[j-1]=1st[j-1],1st[j]
1st[i][0]=i+1
return 1st
#部分代码略
p=b[k][1]
num+=1
print(″第″+str(num)+″个包裹中品种为″+str(k)+″,各物品的序号依次是:″,end=″ ″)
while p!=-1:
print(data[p][0],end=″,″)
p=x[p]
k=data[i][1]
if b[k][0]+data[i][4]>m:
pack(k)
b[k]=[0,-1]
p=
if p==-1:
b[k][1]=i
else:
if data[i][4]>data[p][4]:
b[k][1]=i
else:
q=-1
while
q=p
p=x[p]
x[q]=i
x[i]=p
b[k][0]+=data[i][4]
if b[i][1]!=-1:
pack(i)
if head%4==0:
print(que[head] )
else:
tail=(tail+1) %n
que[tail] =que[head]
A.b | B.c | C.d | D.e |
A.[7, 3, 3, 4, 9, 4] | B.[8, 8, 10, 5, 7, 8] | C.[9, 4, 9, 4, 8, 7] | D.[7, 2, 9, 7, 4, 5] |