题目大意
给出一些用户的PAT的提交记录,现在要求将这些用户排序,规则(规则由优先级排列):
- 用户获得的总分(降序)
- 用户通过的题目数量(降序)
- 用户的id(升序)
输入
每组包含一个测试用例
- 第一行是三个正整数 N ≤ 1 0 4 N\le10^4 N≤104表示用户的数量, K ≤ 5 K\le5 K≤5表示题目的数量, M ≤ 1 0 5 M\le10^5 M≤105表示提交的数量
- 第二行是 K K K个整数,表示每题的总分值,当用户获得对应题的总分时,才能算他这题通过
- 之后有
M
M
M行,每行是用户的提交记录,格式为
用户ID 题目ID 用户在这题获得的分数
,分数为-1表示用户没通过编译器
用户的每一题都取该题的最好记录
用户ID的范围是
[
1
,
N
]
[1, N]
[1,N],题目ID的范围是
[
1
,
K
]
[1, K]
[1,K]
输出
对每个用例输出按题意排好序后的用户信息,格式为:
用户排名 用户ID 用户总分 用户的每题的分数
如果用户的某一题没提交,则在对应的分数上输出-
,如果用户的某一题没通过编译器,则在对应的分数上输出0
如果用户没有提交过,或者提交的所有记录都没通过编译器,那么该用户不参与排序
样例输入
7 4 20
20 25 25 30
00002 2 12
00007 4 17
00005 1 19
00007 2 25
00005 1 20
00002 2 2
00005 1 15
00001 1 18
00004 3 25
00002 2 25
00005 3 22
00006 4 -1
00001 2 18
00002 1 20
00004 1 15
00002 4 18
00001 3 4
00001 4 2
00005 2 -1
00004 2 0
样例输出
1 00002 63 20 25 - 18
2 00005 42 20 0 22 -
2 00007 42 - 25 - 17
2 00001 42 18 18 4 2
5 00004 40 15 0 25 -
解析
一道复杂的排序题,规则弄清楚就比较好写
参考大佬:传送门
这题python会超时
超时的python:
# -*- coding: utf-8 -*-
# @Time : 2019/7/3 13:33
# @Author : ValarMorghulis
# @File : 1075.py
import functools
class node:
def __init__(self):
self.id = 100861
self.rank = -1
self.tot = 0
self.score = [-1 for i in range(5)]
self.show = False
self.acNum = 0
def toString(self):
s = "%d %05d %d" % (self.rank, self.id, self.tot)
return s
def cmp(a, b):
if a.tot != b.tot:
return -1 if a.tot > b.tot else 1
if a.acNum != b.acNum:
return -1 if a.acNum > b.acNum else 1
return -1 if a.id < b.id else 1
def solve():
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
users = [node() for i in range(n + 1)]
for i in range(m):
userId, problemId, s = map(int, input().split())
users[userId].id = userId
users[userId].score[problemId-1] = max(users[userId].score[problemId-1], s)
if s != -1:
users[userId].show = True
elif users[userId].score[problemId-1] == -1:
users[userId].score[problemId-1] = -2
for i in range(1, n + 1):
for j in range(k):
if users[i].score[j] != -1 and users[i].score[j] != -2:
users[i].tot += users[i].score[j]
if users[i].score[j] == a[j]:
users[i].acNum += 1
users = sorted(users[1:], key=functools.cmp_to_key(cmp))
for i in range(n):
users[i].rank = i + 1
if i != 0 and users[i].tot == users[i - 1].tot:
users[i].rank = users[i - 1].rank
for i in range(n):
if users[i].show:
ans = users[i].toString()
for j in range(k):
if users[i].score[j] == -1:
ans += " -"
elif users[i].score[j] == -2:
ans += " 0"
else:
ans += " %d" % users[i].score[j]
print(ans)
if __name__ == "__main__":
solve()