Uniquely grouping objects
I'm creating groups of objects and I'm not really interested in creating a relational database. Basically i am creating a program to group movies for a party and each movie is rated on a 1-5 rating, now no two movies can be at the same party but every party must have at least one 5 star rating movie.
I have knocked out the first part that no two movies can be at the same party by creating unique group IDs using nanotime, however i cannot figure 开发者_如何学Cout how to create the second part by grouping the groups with the ratings. I would appreciate some high level problem solving, but please no code, I would prefer to program it myself, thanks for your help. :D
(if it helps i am using java)
The simple solution would be to group all the movies into a list, sorted by rating descending (thus ensuring that all 5-star movies are at the start). You then iterate over that list, allocating a movie to each party (provided you have more 5-star movies than parties, this will satisfy the condition that all parties need one 5-star movie). You can loop this until all movies have been allocated or until each party has enough movies, whichever comes first.
精彩评论