bludecode-足球队员射门能力排序

47 阅读2分钟

时间限制:C/C++ 1000MS,其他语言 2000MS
内存限制:C/C++ 256MB,其他语言 512MB
难度:简单
出题人:root

描述

球队有n个足球队员参,的次射心训练,每次射门进球用1表示,射失则用0表示,依据如下规则对该n个队员的射门能力做排序
1、进球总数更多的队是射门能力更强
2、若进球总数一样多,则比较最多-次连续进球的个数,最多的队员能力
更强
3、若最多 次连续进球的个数一样多,则比较第一次射失的先居顺序,其
中后射丢的队员更强,若第一次射丢顺序相同,则按继续比较第二次射丢
的顺序,后丢球的队员能力如强,依次类推
4、若前3个规则批序后还能力相等,则队员编与更小的能力更强

输入描述

第1行,足球队员数n,射门训练次数…(队员编号从1开始,依次递增)
第2行,第1-n个队员从第1到m次训练的进球情况,每个队员进球情况为连续的1和0的组合,不同队员用空格分隔
n和m均为正整数,0<n<=103、0<m<=103

输出描述

射门能加从强到弱的队员编号,用空格分隔

用例输入 1 **

4 5
11100 00111 10111 01111

用例输出 1 **

4 3 1 2

用例输入 2 **

2 10
1011100111 1011101101

用例输出 2 **

2 1
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Player {
    int id;
    int totalGoals;
    int maxStreak;
    vector<int> missPositions;

    Player(int id_, const string& shots) : id(id_), totalGoals(0), maxStreak(0) {
        int currentStreak = 0;
        for (int i = 0; i < shots.size(); ++i) {
            if (shots[i] == '1') {
                totalGoals++;
                currentStreak++;
                maxStreak = max(maxStreak, currentStreak);
            } else {
                missPositions.push_back(i);
                currentStreak = 0;
            }
        }
    }

    // 比较函数(从强到弱)
    bool operator<(const Player& other) const {
        if (totalGoals != other.totalGoals)
            return totalGoals > other.totalGoals;
        if (maxStreak != other.maxStreak)
            return maxStreak > other.maxStreak;
        if (missPositions != other.missPositions)
            return missPositions > other.missPositions;  // 越后丢越强
        return id < other.id;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<Player> players;
    for (int i = 1; i <= n; ++i) {
        string s;
        cin >> s;
        players.emplace_back(i, s);
    }

    sort(players.begin(), players.end());

    for (int i = 0; i < players.size(); ++i) {
        if (i > 0) cout << " ";
        cout << players[i].id;
    }
    cout << endl;

    return 0;
}