天天看點

Elo rating system(測試版)

https://en.wikipedia.org/wiki/Elo_rating_system

埃洛等級分系統(Elo Rating System)是指由匈牙利裔美國實體學家阿帕德·埃洛建立的一個衡量各類對弈活動水準的評價方法,是當今對弈水準評估的公認的權威方法。

假設A的分數為(R_A),B的分數為(R_B),那麼A戰勝B的期望為:

E A = 1 1 + 1 0 R B – R A 400 E_A = \frac 1 {1 + 10^{\frac {R_B – R_A} {400} } } EA​=1+10400RB​–RA​​1​

把A和每個人都計算一次期望再求和,然後用總人數減去這個和,就可以當排名的期望:

e x p r a n k A = 13 – ∑ i = 1 n 1 1 + 1 0 R i – R A 400 exprank_A = 13 – \sum_{i = 1}^n \frac 1 {1 + 10^{\frac {R_i – R_A} {400} } } exprankA​=13–i=1∑n​1+10400Ri​–RA​​1​

于是最後A的分數就會變為

f i n a l s c o r e A = o r i g i n a l s c o r e A + k ∗ ( e x p r a n k A – e n d r a n k A ) finalscore_A = originalscore_A + k * (exprank_A – endrank_A) finalscoreA​=originalscoreA​+k∗(exprankA​–endrankA​)

這裡的k是一個系數,暫時取16。

#include<bits/stdc++.h>
using namespace std;
map<string, pair<int, int> > msp;
vector<pair<int, string> > sp;
map<string, double> msd;
map<string, int> ori;
bool cmp(pair<int, string> a, pair<int, string> b){return a.first > b.first;}
int main()
{
    freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    string s;
    double td;
    int ti;
    for (int i = 1; i <= 13; ++i){
        cin >> s >> ti;
        cin >> msp[s].first >> msp[s].second;
        cin >> td;
    }
    for (auto e : msp){
        if (e.second.second == 0){
            sp.push_back(make_pair(e.second.first, e.first));
            continue;
        }
        double exp = 0;
        for (auto e2 : msp){
            if (e2.second.second == 0) continue;
            exp += 1 / (1 + pow(10.0, (e2.second.first - e.second.first) / 400.0));
        }
        exp = 13.0 - exp;
        msd[e.first] = exp;
        ori[e.first] = int(16.0 * (exp - e.second.second));
        sp.push_back(make_pair(int(e.second.first + 16.0 * (exp - e.second.second)), e.first));
    }
    sort(sp.begin(), sp.end(), cmp);
    for (auto e : sp){
        cout << e.second << " " << ori[e.second] << " " << e.first << " " << msd[e.second] << endl;
    }
    fclose(stdin); fclose(stdout);
    return 0;
}