赞
踩
示例1
输入:
5 4
1
1
2
3
5
1 2 3
1 4
3 4 5
2 3 4
输出:
3
4
1
2
示例2
输入:
3 3
3
1
5
1 2 3
1 2 3
1 2 3
输出:
1
2
3
思路:
简单排序问题
class TestCase:
def solution(self, test_case_pri_list, m):
idx_list = [i for i in range(m)]
# 值相同时,索引保持从小到大
idx_list.sort(key=lambda i: test_case_pri_list[i], reverse=True)
# 恢复测试用例ID
for idx in idx_list:
print(idx+1)
if __name__ == '__main__':
test_case = TestCase()
while True:
try:
n, m = list(map(int, input().strip().split()))
feature_pri_list = []
test_case_pri_list = []
for i in range(n):
feature_pri_list.append(int(input().strip()))
for i in range(m):
val = [feature_pri_list[j-1] for j in list(map(int, input().strip().split()))]
test_case_pri_list.append(sum(val))
test_case.solution(test_case_pri_list, m)
except KeyboardInterrupt:
break
lambda排序:
test_case = [(ID, pri)]
test_case.sort(key=lambda i:(i[1]*(-1), i[0]))
先按照优先级降序排序,(优先级相同)再按照ID升序排序
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。