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

头条就做出来两个。。。。
贴一下:
第一题:
(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

相关推荐

09-10 21:07
已编辑
南京理工大学 C++
第一题bfs,20min搞定第二题,掩码,二进制操作通过24%(把j打成i)调了一个半小时第三题,没时间看了(直接cout第一个用例过10%)
来个白菜也好啊qaq:牛啊,第三题打印第一个用例居然可以拿百分之10不过第二题瞎寄吧写可以拿百分之36的分(两个字符串的string(0,12)比较,一样给yes,不一样给no)
投递华为技术有限公司等公司10个岗位
点赞 评论 收藏
分享
08-06 08:33
四川大学 Java
OPPO官方内推:卧槽!!!啥破公司啊!!!
投递OPPO等公司10个岗位
点赞 评论 收藏
分享
08-01 19:22
已编辑
前台
点赞 评论 收藏
分享
09-10 18:19
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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