1A 王者荣耀

https://pintia.cn/problem-sets/1573502166818291712/exam/problems/1573502371857018880

image.png

image.png

#include
#include
#include

using namespace std;
struct score{
    int i = 0;
    int p = 0;
    int q = 0;
};

bool operator <(score const &a,score const & b){
    if (a.p != b.p) {
        return a.p > b.p;
    }
    return a.q > b.q;
}


void input(vector &info,int row)
{
    for(int i = 0; i< row; ++i){
        int x = 0;
        int y = 0;
        int a = 0;
        int b = 0;
        
        cin>>x>>y>>a>>b;
        if(a == 2){
            ++info[x - 1].p;
        }else{
            ++info[y - 1].p;
        }
        info[x - 1].q += a;
        info[y - 1].q += b;
    }
}

void output(vector const &result)
{
    cout<<(int)result[0];
    for (int i = 1; i < result.size(); ++i) {
        cout<<'\n';
        cout<<(int)result[i];
    }
}

int main(){
    int size = 0;
    int m = 0;
    cin>>size>>m;

    if(size == 1){
        cout<<1;
        return 0;
    }
    
    vector info;
    info.resize(size);
    
    int const row = size * (size-1)/2;
    for (int i = 0; i < size; ++i) {
        info[i].i = i;
    }
    
    input(info,row);
    
    sort(info.begin(), info.end());
    
    vector result;
    result.resize(size);
    result[info[0].i] = 1;
    int ranking = 1;
    score * pre = & info[0];
    for (int i = 1; i < info.size(); ++i) {
        if (pre->p != info[i].p || pre->q != info[i].q) {
            ranking = i + 1;
        }
        if (ranking <= m) {
            result[info[i].i] = true;
        }
        pre = & info[i];
    }
    
    output(result);
    
    return 0;
}

你可能感兴趣的:(1A 王者荣耀)