从分数列表生成标准的竞争排名 [英] Generate standard competition rankings from a list of scores

查看:256
本文介绍了从分数列表生成标准的竞争排名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于分数的清单(例如5,5,4,2,2,0),我想找返回标准竞争排名(1,1,3,4,4,6)。

维基百科的排名页面,这里的SRC的总结:

  

标准竞争中的排名(1224的排名)

     

在竞争中的排名,是比较平等的物品上获得相同的   排名号,然后间隙被留在排名号码。该   被冷落在此间隙中排名号码数量是少了一个   比的项目相比相等的数量。等价地,每   项的排序号码是1加上的项数排它上面。   这个排名的策略是经常采用的比赛,因为它   意味着,如果两个(或更多)的竞争者扎在一个位置   排名中,所有这些排名低于他们的立场不受影响   (也就是说,竞争对手只排第二,如果只有一个人的分数   比他们好,第三个,如果正好有两个人的分数比他们更好,   第四,如果正好三个人得分比他们更好,等等)。

     

因此​​,如果阿居B和C(其比较相等)的前方这两者都是   排名领先的D,则A获得排名1号(第一),B得到   排名2号(二联),C也得到名次2号   (联合二)和D被排名4号(第四)。在这种情况下,   没有人会获得排行榜第3(第三),这将保持原样   的间隙。

code。在任何一种语言将是非常有益的。

顺便说一句我很想看到其他类型的排序算法(修改后的竞争排名中,密集的排名,依次排名和分数排名)。

解决方案

下面是如何做到这一点:

  • 设置排名[0] 1
  • 对于每个指数分数 -list
    • 如果比分[I] 等于比分[I-1] ,他们应该有相同的ranknig:
      • 排名[I] = ranknig [I-1]
    • 在其他的排名应该等于当前索引:
      • 排名[I] = I + 1
        + 1 由于0型indecies与1型排名)

下面是一个Java的实现:

  //设置一些样本分数。
INT []分值= {5,5,4,2,2,0};

//初始化排名阵列
INT []排名=新INT [scores.length]

//在每个位置填写
排名[0] = 1;
的for(int i = 1; I< rankings.length;我++)
    排名[I] =分数[I] ==分数[I-1]?排名[I-1]:1 + 1;

//排名= [1,1,3,4,4,6]
 

Given a list of scores (e.g. 5, 5, 4, 2, 2, 0), I'm looking to return the standard competition rankings (1, 1, 3, 4, 4, 6).

From Wikipedia's ranking page, here's a summary of SRC:

Standard competition ranking ("1224" ranking)

In competition ranking, items that compare equal receive the same ranking number, and then a gap is left in the ranking numbers. The number of ranking numbers that are left out in this gap is one less than the number of items that compared equal. Equivalently, each item's ranking number is 1 plus the number of items ranked above it. This ranking strategy is frequently adopted for competitions, as it means that if two (or more) competitors tie for a position in the ranking, the position of all those ranked below them is unaffected (ie, a competitor only comes second if exactly one person scores better than them, third if exactly two people score better than them, fourth if exactly three people score better than them, etc).

Thus if A ranks ahead of B and C (which compare equal) which are both ranked ahead of D, then A gets ranking number 1 ("first"), B gets ranking number 2 ("joint second"), C also gets ranking number 2 ("joint second") and D gets ranking number 4 ("fourth"). In this case, nobody would get ranking number 3 ("third") and that would be left as a gap.

Code in any language would be really helpful.

As an aside I'd be interested to see algorithms for the other ranking types (modified competition ranking, dense ranking, ordinal ranking and fractional ranking).

解决方案

Here's how to do it:

  • Set ranking[0] to 1.
  • For each index i in the score-list
    • If score[i] equals score[i-1] they should have same ranknig:
      • ranking[i] = ranknig[i-1]
    • else the ranking should equal the current index:
      • ranking[i] = i + 1
        (+ 1 due to 0-based indecies and 1-based ranking)

Here's a sample implementation in Java:

// Set up some sample scores.
int[] scores = { 5, 5, 4, 2, 2, 0 };

// Initialize a ranking array
int[] rankings = new int[scores.length];

// Fill in each position
rankings[0] = 1;
for (int i = 1; i < rankings.length; i++)
    rankings[i] = scores[i] == scores[i-1] ? rankings[i-1] : i + 1;

// rankings = [1, 1, 3, 4, 4, 6]

这篇关于从分数列表生成标准的竞争排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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