pat_BL_1015
来源:互联网 发布:淘宝添加客服 编辑:程序博客网 时间:2024/05/11 02:22
2016_8_28
有三个测试点超时了,感觉思路很简单不知道该怎么优化,有没有用python写过这道题的朋友呢,帮忙看看我这个思路有没有问题啊。
p.s.找到一个不用pandas进行按列排序的方法,这里附上网址,写的很详细,以后能用到
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=429659&id=3140368
# -*- coding: utf-8 -*-"""Created on Mon Aug 22 19:08:13 2016@author: hanzy"""if __name__ == "__main__": info = raw_input() roop1,bottom1,top1 = info.split(' ') roop = int(roop1);bottom = int(bottom1);top = int(top1) type1 = [] type2 = [] type3 = [] type4 = [] while(roop > 0): stuinfo = raw_input() stuid1,stude1,stucai1 = stuinfo.split(' ') stuid = int(stuid1);stude = int(stude1);stucai = int(stucai1); if stude >= bottom and stucai >= bottom: if stude >= top and stucai >= top: type1.append([stuid,stude,stucai]) elif stude >= top and stucai < top: type2.append([stuid,stude,stucai]) elif stude < top and stucai < top and stude >= stucai: type3.append([stuid,stude,stucai]) else: type4.append([stuid,stude,stucai]) roop -= 1 type1aftsort = sorted(type1,key = lambda x: (-(x[1]+x[2]),-x[1],x[0])) type2aftsort = sorted(type2,key = lambda x: (-(x[1]+x[2]),-x[1],x[0])) type3aftsort = sorted(type3,key = lambda x: (-(x[1]+x[2]),-x[1],x[0])) type4aftsort = sorted(type4,key = lambda x: (-(x[1]+x[2]),-x[1],x[0])) print len(type1aftsort)+len(type2aftsort)+len(type3aftsort)+len(type4aftsort) for i in range(len(type1aftsort)): print type1aftsort[i][0],type1aftsort[i][1],type1aftsort[i][2] for i in range(len(type2aftsort)): print type2aftsort[i][0],type2aftsort[i][1],type2aftsort[i][2] for i in range(len(type3aftsort)): print type3aftsort[i][0],type3aftsort[i][1],type3aftsort[i][2] for i in range(len(type4aftsort)): print type4aftsort[i][0],type4aftsort[i][1],type4aftsort[i][2]
0 0