算法分组 [英] Algorithm for Grouping

查看:129
本文介绍了算法分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图帮助别人写一个程序,我想会很容易,但当然永远是:)

I am trying to help someone write a program that I thought would be easy, but of course it never is :)

我想采取一个类名册(通常10-20同学之间)和用途不同唯一配对关每个同学另一个是让独特的群体。因此,在一类10人,可以有9组。

I am trying to take a class roster (usually between 10-20 students) and effectivly uniquely pair off each classmate to another to make unique groups. Therefore in a class of 10 people, you can have 9 groups.

有需要能够处理学生奇数太,添加到我的混乱。

It needs to be able to handle odd number of students too, adding to my confusion.

我看在Java中这样做,但这是灵活的。在一个算法的方式任何想法,以保证)不是无限的循环(结尾有2人谁已经被合作伙伴)和b)我的目标进行比较有效的时间比空间,因为班级规模会很小!

I was looking at doing this in Java, but that is flexible. Any ideas on an algorithmic way to guarantee a)not infinite looping (ending with 2 people who have already been partners) and b) I am aiming for more efficent time than space, since class size will be small!

谢谢!

推荐答案

您希望创建与每个学生作为一个节点,一个完整的图形,然后随机选择边,将其插入到一组唯一的。

You want to create a complete graph with each student as a node, then randomly select edges and insert them into a unique set.

在接下来的拉,你想要做同样的事情,但现在如果边缘已经被选中,抛弃和重新选择。

On the next "pull", you want to do the same thing, except now if the edge has already been selected, discard and reselect.

这篇关于算法分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆