时间空间都击败所有人了(C语言)
2025-06-30 10:21:34
发布于:浙江
44阅读
0回复
0点赞
#include <stdio.h>
#include <stdlib.h>
typedef struct {
    int id;
    int solved;
    int penalty;
} Team;
int compare(const void *a, const void *b) {
    Team *teamA = (Team *)a;
    Team *teamB = (Team *)b;
    
    if (teamA->solved != teamB->solved) {
        return teamB->solved - teamA->solved;
    } else if (teamA->penalty != teamB->penalty) {
        return teamA->penalty - teamB->penalty;
    } else {
        return teamA->id - teamB->id;
    }
}
int main() {
    int n;
    scanf("%d", &n);
    
    Team teams[101];
    for (int i = 1; i <= n; i++) {
        teams[i-1].id = i;
        teams[i-1].solved = 0;
        teams[i-1].penalty = 0;
    }
    
    for (int i = 1; i <= n; i++) {
        int m;
        scanf("%d", &m);
        
        int wrongs[14] = {0};
        int solved_time[14] = {0};
        
        for (int j = 0; j < m; j++) {
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            
            if (c == 1 && solved_time[b] == 0) {
                solved_time[b] = a;
                wrongs[b]++;
            } else if (c == 0 && solved_time[b] == 0) {
                wrongs[b]++;
            }
        }
        
        for (int j = 1; j <= 13; j++) {
            if (solved_time[j] > 0) {
                teams[i-1].solved++;
                teams[i-1].penalty += solved_time[j] + (wrongs[j] - 1) * 15;
            }
        }
    }
    
    qsort(teams, n, sizeof(Team), compare);
    
    for (int i = 0; i < n; i++) {
        printf("%d", teams[i].id);
        if (i < n - 1) {
            printf(" ");
        }
    }
    printf("\n");
    
    return 0;
}
这里空空如也







有帮助,赞一个