分值 : 25 难度 : 中等题 思路 : 结构体排序 坑点 : 会有很无聊的用户ac代码上传多次,但是ac的题目不能乱加。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
#include <iostream>#include <algorithm>using namespace std;typedef struct Node{ int id ; int score[6]={-1,-1,-1,-1,-1,-1}; int ac=0; int flag = 0 ; int sum = 0 ; int rank = 0 ;}Nodes;Nodes data[100001];int full_mark[6];int N , K , Q ;bool cmp(Node a ,Node b){ if(a.flag != b.flag) return a.flag> b.flag; if(a.sum != b.sum ) return a.sum > b.sum ; if(a.ac!= b.ac) return a.ac >b.ac ; return b.id > a.id ;}int main() { cin >> N>> K >>Q ; for(int i = 1 ; i<= K ; i++) cin >>full_mark[i] ; for(int i = 0 ; i< Q ; i++) { int id , timu , Score ; scanf("%d %d %d",&id , &timu , &Score); if(data[id].score[timu] != full_mark[timu] &&Score == full_mark[timu]) data[id].ac++ ; data[id].id = id ; if(Score!=-1) data[id].flag = 1 ; if(Score<= 0 && data[id].score[timu] <=0) data[id].score[timu] = 0; else if(Score>0 && data[id].score[timu]<= Score) data[id].score[timu] = Score; } for(int i = 1 ; i<=N ; i++ ) { for(int j = 1 ; j<=K ; j++) { if(data[i].score[j]!=-1) data[i].sum+= data[i].score[j] ; } } sort(data+1,data+N+1,cmp) ; data[1].rank = 1 ; for(int i = 2 ; i<=Q ; i++) { if(!data[i].flag)break ; if(data[i].sum == data[i-1].sum) data[i].rank =data[i-1].rank; else data[i].rank = i ; } for(int i = 1 ; i<= Q;i++) { if(!data[i].flag) break ; printf("%d %05d %d" , data[i].rank , data[i].id , data[i].sum) ; for(int j = 1 ; j<=K ; j++) { if(data[i].score[j] ==-1) printf(" -"); else printf(" %d",data[i].score[j]); } printf("\n"); }}