algorithm - "Waiting lists problem"

标签 algorithm language-agnostic theory

A number of students want to get into sections for a class, some are already signed up for one section but want to change section, so they all get on the wait lists. A student can get into a new section only if someone drops from that section. No students are willing to drop a section they are already in unless that can be sure to get into a section they are waiting for. The wait list for each section is first come first serve.

Get as many students into their desired sections as you can.

上述问题可能会很快演变成僵局。我的问题是;这个问题有已知的解决方案吗?


一个简单的解决方案是依次进入每个部分,并强制等待名单中的第一个学生进入该部分,然后检查是否有人在事情解决后退出(O(n) 或更多部分)。这适用于某些情况,但我认为可能有更好的选择,包括强制一个以上的学生进入一个部分(学生人数为 O(n) 或更多)和/或一次对多个部分进行操作(O (不好):-)

最佳答案

好吧,这只是在类的有向图中找到循环,对吗?每个链接都是一个想要从一个节点转到另一个节点的学生,每当你找到一个循环时,你就删除它,因为这些学生可以相互解决他们的需求。当你脱离循环时,你就完成了。

关于algorithm - "Waiting lists problem",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/429839/

相关文章:

java - 改进素筛算法

algorithm - 确定矩阵中的线、圆、三角形或矩形

language-agnostic - 在 CQRS 工作流中获取另一个域的数据的推荐方法是什么?

c++ - 预期的无限递归,不返回函数

java - 两种指针技术中的贪心算法(快跑者和慢跑者)

java - 用于存储 2D 数组值的内存效率最高的数据结构 (Java)

language-agnostic - 提高代码可读性

language-agnostic - 当 write 或 read 返回的请求少于请求时如何调用它?

computer-science - 图灵机可以越过磁带的开头吗?

list - 当不需要保留顺序时,可以编码为更少的位吗?