简体   繁体   English

Skiena算法设计

[英]Skiena Design on Algorithm

I am stuck on a problem in Skiena's Design on Algorithms.I don't know if my solution is right. 我在Skiena的算法设计中遇到了问题。我不知道我的解决方案是否正确。

5-18. 5-18。 Consider a set of movies M_1, M_2,.. M_k. 考虑一组电影M_1,M_2,... M_k。 There is a set of customers, each one of which indicates the two movies they would like to see this weekend. 有一组客户,每个客户都指出他们希望在本周末看到的两部电影。 Movies are shown on Saturday evening and Sunday evening. 电影将在周六晚上和周日晚上播放。 Multiple movies may be screened at the same time. 可以同时屏蔽多部电影。 You must decide which movies should be televised on Saturday and which on Sunday, so that every customer gets to see the two movies they desire. 您必须决定哪些电影应该在周六播出,哪些电影应该在周日播出,这样每个顾客都可以看到他们想要的两部电影。 Is there a schedule where each movie is shown at most once? 是否有一个每个电影最多只显示一次的时间表? Design an efficient algorithm to find such a schedule if one exists. 设计一种有效的算法来查找这样的计划(如果存在)。

Solution: We have a set {M1,M2..Mk} for movies and a set {C1,C2,..Cp} for costumers.We connect with an edge 2 films that C1 desires to watch,connect with an edge 2 movies that C2 wants to watch and so on.The set of movies become a connected graph.I want to verify if it is a bipartite graph such as 2 favorite movies could not be showed in the same night(color 2 favorites movies with different colors).If it is,we show all the movies colored with 1st color on Saturday and 2nd color an Sunday.problem solved.But in case it isn't what should I do? 解决方案:我们为电影设置了一套{M1,M2..Mk},为客户设置了一套{C1,C2,.. Cp}。我们连接了一部边缘的2部电影,C1希望观看,连接边缘2部电影C2希望观看等等。电影集成为连接图。我想验证它是否是一个二分图,如2个最喜欢的电影无法在同一个晚上显示(颜色2个不同颜色的收藏电影)如果是的话,我们会在周六显示第一种颜色的彩色电影,在星期日显示第二种颜色。问题解决了。但是如果不是我该怎么办?

The question mentions that we can show movies at the same time. 问题提到我们可以同时播放电影。 Take two sets Sat and Sun. 周六和周日两套。 For each customer check if the movies he want to see are in different sets, if they aren't put one at random in Sat and one in Sun and continue. 对于每个客户,检查他想要看的电影是否在不同的集合中,如果他们没有在星期六随机放置一个,在阳光下放一个并继续。 In case they are in the same set, put any one of them in the other Set. 如果它们在同一组中,则将其中任何一个放入另一组中。 In worst case each movie will be shown on both Sat and Sun. 在最坏的情况下,每部电影都将在周六和周日上映。

Create a graph from movies M1, M2, ..., Mk. 从电影M1,M2,...,Mk创建图表。 If Mi and Mj is indicated by a customer, we put an edge between Mi and Mj. 如果Mi和Mj由客户指示,我们在Mi和Mj之间设置优势。 Repeat this for all customers. 对所有客户重复此操作。 Then use two-color algorithm to bipartite movies into two sets, one is Saturday and the other is Sunday. 然后使用双色算法将电影分成两组,一组是星期六,另一组是星期日。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM