2 回答
TA贡献1805条经验 获得超10个赞
首先了解self
python。
其次了解作业排序问题。
然后看下面的代码
class Scheduling:
def schedule(self, n, deadline, jobs):
# max number of jobs you can schedule is the max deadline available.
filledJobs = ['dummy']*max(deadline);
i = 0
# start assigning the jobs in a greeedy way
while i < n:
job = jobs[i]
j = deadline[i]
# assign the job from the last deadline
while j > 0:
if(filledJobs[j-1] == 'dummy'):
filledJobs[j-1] = job
break
j = j - 1
i = i + 1
return filledJobs
def main():
sins = Scheduling()
n = 4
deadline = [1,1,2,2]
# assuming jobs are sorted w.r.t profits
# I represented the jobs with string to be clear
jobs = ['a', 'b', 'c', 'd']
sjobs = sins.schedule(n, deadline, jobs)
print (sjobs)
if __name__ == "__main__":
main()
添加回答
举报