![](https://i.imgur.com/jrogY9u.jpg)
Re: [商管] 105 清大服科 程式題
![](https://i.imgur.com/jrogY9u.jpg)
: 代友po文
: 想問一下這題
: 他初始條件給的是第一輪就能做完
: 那下面說要再做往回的第二輪是什麼意思呢?
: 然後這種題目能用中文敘述回答嗎
: 謝謝~
提供一下我的答案,大家一起來debug
studentPreference[300][10] //列代表學生,行代表該學生的喜好順序
preference[10] //拿來產生喜好順序用
for i = 1 to 10
preferenec[i] = 1
for i = 1 to 300
shuffle(preference)
for j = 1 to 10
studentPreference[i][j] = preference[j]
studentOrder[300] //學生的優先順序
for i = 1 to 300
studentOrder[i] = i
shuffle(studentOrder)
studentCourse1[300]
studentCourse2[300] //儲存每個學生最後選到的課程
courseCount[10] //儲存每個課程現在有多少學生佔用
//pass 1
for i = 1 to 10
courseCount = 0
for i = 1 to 300
student = studentOrder[i]
for j = 1 to 10
course = studentPreference[student][j]
if (courseCount[course] < 30)
studentCourse1[student] = course
courseCount[course] = courseCount[course] + 1
break
for i = 1 to 10
courseCount[i] = 0
//pass 2
for i = 300 to 1
student = studentOrder[i]
for j = 1 to 10
course = studentPreference[student][j]
if (courseCount[course] < 30)
studentCourse2[student] = course
courseCount[course] = courseCount[course] + 1
break
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.85.61.62
※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1486109155.A.931.html
※ 編輯: yupog2003 (219.85.61.62), 02/03/2017 16:19:03
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):