头条算法题,,就做出两个,,泪目

头条就做出来两个。。。。
贴一下:
第一题:
(m,n) =map(lambda x:int(x), raw_input().split(','))

seats = []
for i in range(m):
    seats.append(map(lambda x:int(x),raw_input().split(',')))

maxGroupn = 0;
Groupn = 0;


def search(i,j):
    if i<0 or j<0 or i>=m or j>=n or seats[i][j]<=0:
        return 0
    seats[i][j]=-1;
    count=1+search(i+1,j)+search(i-1,j)+search(i,j-1)+search(i,j+1)+search(i-1,j-1)+search(i-1,j+1)+search(i+1,j-1)+search(i+1,j+1)
    return count;
    
for i in range(m):
    for j in range(n):
        curGroupn = search(i,j)
        if curGroupn>0:
            Groupn+=1
            if curGroupn > maxGroupn:
                maxGroupn = curGroupn

print str(Groupn)+','+str(maxGroupn)
第二题:
m = input()

words = []
for i in range(m):
    words += map(lambda item:map(lambda x:int(x),item.split(',')),raw_input().split(';'))
    
words.sort(lambda t1,t2:t1[0]-t2[0])
i=1
while i < len(words):
    if i>0 and words[i][0]<=words[i-1][1]:
        if words[i][1] > words[i-1][1]:
            words[i-1][1] = words[i][1]
        del words[i]
    else:
        i+=1

strn = ""
for k1,k2 in words:
    strn += str(k1)+','+str(k2)+";"

print strn[:-1]

#笔试题目#
全部评论
用C,输入处理都写的快吐了。。。java一个split解决一切。。
点赞 回复 分享
发布于 2018-08-12 12:31
才25行。。。下次也用python了
点赞 回复 分享
发布于 2018-08-12 12:22
python写的好短呀,leetcode上的很多答案都是python的
点赞 回复 分享
发布于 2018-08-12 12:22
python是简洁啊
点赞 回复 分享
发布于 2018-08-12 12:12

相关推荐

08-15 01:16
Python
Java小萌新新萌小...:照片不用整这么大的 而且你的照片截歪了 你想找专业对口的 那普通话证写在这里其实没有什么必要 就是看着内容多点 而且里面字体大小也不一样 修改一下排版 有很多空间可以再利用一下 字大一点 不然现在这样观感不太好 再就是项目好好优化一下 加油
点赞 评论 收藏
分享
头像
08-05 15:59
已编辑
门头沟学院 运维工程师
哈哈哈,你是老六:感觉这女的就是把你当免费的劳动力
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务