Javascript 添加和删除人员的循环算法
好的,在这个代码笔中,我已经找到了一个循环锦标赛调度算法:Javascript 添加和删除人员的循环算法,javascript,algorithm,Javascript,Algorithm,好的,在这个代码笔中,我已经找到了一个循环锦标赛调度算法: var玩家=[ { playerName:'人1', }, { playerName:'人2', }, { playerName:'人3', }, { playerName:'人4', }, { playerName:'人5', }, { playerName:'人6', }, { playerName:'人7', }, { playerName:'人8', }, { playerName:'人9', }, { playerName:'
var玩家=[
{
playerName:'人1',
},
{
playerName:'人2',
},
{
playerName:'人3',
},
{
playerName:'人4',
},
{
playerName:'人5',
},
{
playerName:'人6',
},
{
playerName:'人7',
},
{
playerName:'人8',
},
{
playerName:'人9',
},
{
playerName:'人10',
},
{
playerName:'人11',
},
{
playerName:'人12',
},
{
playerName:'人13',
},
{
playerName:'人14',
},
{
playerName:'人15',
},
{
playerName:'人16',
},
];
var numberOfRounds=players.length-1;
函数生成器unds(){
对于(i=0;i
我用它来快速约会,即使你可以和每个人约会
我的问题是:
在每一轮之后,新的人可以参加活动或离开活动(如果他们感到无聊;)
注意:迟到者不需要和每个人约会,因为他们已经错过了x轮
注2:如果有很多人离开,最好限制轮次的数量,这样人们就不需要在约会之间等待那么长的时间了对于两部分匹配问题,如男女分开的快速约会,可以使用最大流算法 在4层中构建图形:
- 用边缘容量1完全连接第1层到第2层
- 用边缘容量1完全连接第2层至第3层
- 用边缘容量1完全连接第3层至第4层
启发性:您可以修改最大流量算法,将日期最少或轮次最多的人排在第一位,这样,若存在奇数人,则最新的人和同一个人都不会排在第一位 扩展:通过过滤在第2层和第3层之间添加的边集,可以实现首选项来限制潜在匹配集 时间:绝对糟糕。可能介于O(n^3)和O(n^6)之间,具体取决于max flow实现的好坏,但谁在乎16个人呢 github上的一些javascript max flow软件包,从未尝试过。祝你好运:
对于任何人对任何人匹配问题,必须用更复杂的Blossom算法替换最大流算法 与max-flow一样,该算法通过查找增广路径,然后修改其当前匹配集来迭代地细化匹配 此算法的输入为:
- 为每个人添加一个节点
- 完全连接所有节点
var players = [
{
playerName: 'Person 1',
},
{
playerName: 'Person 2',
},
{
playerName: 'Person 3',
},
{
playerName: 'Person 4',
},
{
playerName: 'Person 5',
},
{
playerName: 'Person 6',
},
{
playerName: 'Person 7',
},
{
playerName: 'Person 8',
},
{
playerName: 'Person 9',
},
{
playerName: 'Person 10',
},
{
playerName: 'Person 11',
},
{
playerName: 'Person 12',
},
{
playerName: 'Person 13',
},
{
playerName: 'Person 14',
},
{
playerName: 'Person 15',
},
{
playerName: 'Person 16',
},
];
var numberOfRounds = players.length - 1;
function generateRounds() {
for(i = 0; i < numberOfRounds; i++) {
document.write('<h1 class="round">'+'Round ' + (i+1) + '</h1>');
for (var j = 0; j < players.length / 2; j++) {
document.write('<div class="match">' + players[j].playerName + " - " + players[players.length - 1 - j].playerName +'</div>');
}
players.splice(1, 0, players[15]);
players.pop();
}
}
generateRounds();