Python:1015 德才论
发布日期:2021-05-07 19:52:44 浏览次数:13 分类:技术文章

本文共 1046 字,大约阅读时间需要 3 分钟。

文章目录

一、题目

在这里插入图片描述在这里插入图片描述

二、代码

分析

题目不是很难,关键在于排序
按照题目分成四个列表,代表四类考生,然后分别对列表里的考生按照规则排序即可
关于排序可以借助 列表的 sort 方法
具体可参考:[sort 方法详解](https://blog.csdn.net/nanhuaibeian/article/details
/99656250)

注意:

感觉代码已经够简洁了,用内置函数完全可以解决,但是还是存在两个测试点没有超时,郁闷,翻看博客,应该是 python 的性能所致
在这里插入图片描述

N, L, H = map(int, input().split())num1 = []num2 = []num3 = []num4 = []def printf(num):    if num:        for i in num:            print("%d %d %d" % (i[0], i[1], i[2]))for i in range(N):    temp = list(map(int, input().split()))    if temp[1] >= L and temp[2] >= L:        if temp[1] >= H and temp[2] >= H:            num1.append(temp)        elif temp[1] >= H and temp[2] < H:            num2.append(temp)        elif temp[1] >= temp[2]:            num3.append(temp)        else:            num4.append(temp)num1.sort(key=lambda x:(-(x[1]+x[2]),-x[1],x[0]))num2.sort(key=lambda x:(-(x[1]+x[2]),-x[1],x[0]))num3.sort(key=lambda x:(-(x[1]+x[2]),-x[1],x[0]))num4.sort(key=lambda x:(-(x[1]+x[2]),-x[1],x[0]))print(len(num1) + len(num2) + len(num3) + len(num4))printf(num1)printf(num2)printf(num3)printf(num4)
上一篇:Pygame:convert 和 convert_alpha 的简单辨析
下一篇:一篇文章带你搞定 Python 中 sort 方法与 sorted 函数

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年03月28日 11时13分06秒