pat_BL_1015

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值