首页 > 4.11网易互娱服务端笔经
头像
whime1024
发布于 2020-04-11 23:30
+ 关注

4.11网易互娱服务端笔经

四道题情况是100%,100%,0%,80%。
1.九进制加法,AC

"""
在太空深处,生活着这样一群外星人,他们左手有4个手指,右手有5个手指,所以自然地,他们习惯于采用9进制记数。
不过,这些外星人还没有点亮“计算机”科技,所以向地球上的你发出了求助,希望你帮他们设计一款可以用来完成9进制加法的程序。
"""
#
# 接收两个表示9进制数的字符串,返回表示它们相加后的9进制数的字符串
# @param num1 string字符串 第一个加数
# @param num2 string字符串 第二个加数
# @return string字符串
#
class Solution:
    def add(self, num1, num2):
        # write code here
        len1 = len(num1)
        len2 = len(num2)
        i = len1
        j = len2
        tmp = 0
        jinwei = 0
        firstpart = ''
        secondpart = ''
        if '.' not in num1:
            if '.' not in num2:
                pass
            else:
                secondpart = num2.split('.')[1]
                j=num2.rfind('.')
        else:
            if '.' not in num2:
                secondpart = num1.split('.')[1]
                i=num1.rfind('.')
            else:
                # 都包含小数位,先计算小数位部分
                i=len1;j=len2
                size1=i-num1.find('.')
                size2=j-num2.find('.')
                minsi***(size1,size2)
                i-=1
                j-=1
                while minsize!=size1:
                    size1-=1
                    tmp = int(num1[i]) + jinwei
                    jinwei = tmp // 9
                    secondpart += str(tmp % 9)
                    i -= 1
                while minsize!=size2:
                    size2-=1
                    tmp = int(num2[j]) + jinwei
                    jinwei = tmp // 9
                    secondpart += str(tmp % 9)
                    j -= 1
                while num1[i] != '.' and num2[j] != '.':
                    tmp = int(num1[i]) + int(num2[j]) + jinwei
                    secondpart += str(tmp % 9)
                    jinwei = tmp // 9
                    i -= 1
                    j -= 1

                secondpart=secondpart[::-1]
        i-=1
        j-=1
        # 计算整数部分
        while i>=0 and j>=0:
            tmp=int(num1[i])+int(num2[j])+jinwei
            firstpart+=str(tmp%9)
            jinwei=tmp//9
            i -= 1
            j -= 1
        while i>=0:
            tmp = int(num1[i]) + jinwei
            jinwei = tmp // 9
            firstpart += str(tmp % 9)
            i -= 1
        while j>=0:
            tmp = int(num2[j]) + jinwei
            jinwei = tmp // 9
            firstpart += str(tmp % 9)
            j -= 1
        if jinwei:
            firstpart+=str(jinwei)
        firstpart=firstpart[::-1]
        if secondpart=='':
            return firstpart
        else:
            return firstpart+'.'+secondpart

if __name__ == '__main__':
    so=Solution()
    print(so.add('0.25','0.75'))

2.聪明的厂长,AC

"""
厂长阿雄需要根据工厂里每个员工的劳动技能等级来分配每天的工作任务。
一个工作任务只能由劳动技能等级大于等于该任务难度的员工来完成,且同一天里一个员工只能对应一个工作任务,一个工作任务只能由一个员工来完成。
员工i的劳动技能等级由整数Wi来表示,工作任务i的任务难度由整数Ti,来表示。
聪明的你能帮助阿雄分配今天的工作任务么?
"""
n=int(input())
w=list(map(lambda x:int(x),input().split(' ')))
t=list(map(lambda x:int(x),input().split(' ')))
m=int(input())

# 排序之后,由劳动技能最小的员工先选择任务,剩下可选的任务交给下一个较大劳动技能的员工选择
# 累乘每次可选择的任务即为所求
w.sort()
t.sort()
choice=0
index=0
flag=False
res=1
for i in w:
    while not flag and i>=t[index]:
        choice+=1
        index+=1
        if index==len(t):
            flag=True
    res*=choice
    choice-=1
print(res%m)

3.组队,不会,求解答。
4.整理快递盒,80%,只排了序,应该还需要使用最长单调递增子序列的算法求解,厚脸皮贴下代码。

"""
日常收快递留下一堆快递盒占地方。现在有N个快递盒,盒子不做翻转,每个盒子有自己的长宽高数据,
都以整数形式(L,W,H)出现。将小盒子整理到大盒子里面(小盒子的长宽高都小于大盒子)。
要求快递盒一个套一个(即,打开一个大盒子最多只能看到一个小盒子),最多能整理多少个盒子打包到一起。
"""
# @param boxes int整型二维数组
# @return int整型
#
class Solution:
    def maxBoxes(self, boxes):
        # write code here
        if boxes==[]:
            return 0
        tmp = []
        sort_box = []
        boxes = sorted(boxes, key=lambda x: x[-1])
        tmpboxes = []
        h = boxes[0][-1]
        for box in boxes:
            if box[-1] == h:
                tmp.append(box)
            else:
                tmpboxes.extend(sorted(tmp, key=lambda x: x[-2]))
                tmp = []
                tmp.append(box)
                h = box[-1]
        tmpboxes.extend(sorted(tmp, key=lambda x: x[-2]))
        tmp = []
        boxes = tmpboxes
        tmpboxes = []
        # print(boxes[0])
        h = boxes[0][-1]
        w = boxes[0][-2]
        for box in boxes:
            if box[1] == w and box[2]==h:
                tmp.append(box)
            else:
                tmpboxes.extend(sorted(tmp, key=lambda x: x[0]))
                tmp = []
                tmp.append(box)
                h = box[-1]
                w = box[-2]
        tmpboxes.extend(sorted(tmp, key=lambda x: x[0]))
        boxes = tmpboxes

        current=boxes[0]
        res=1
        for box in boxes:
            if current[0]<box[0] and current[1]<box[1] and current[2]<box[2]:
                res+=1
                current=box
            else:
                pass
        return res

if __name__ == '__main__':
    so=Solution()
    print(so.maxBoxes([[5,4,3], [5,4,5], [6,6,6]]))

全部评论

(7) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

热门推荐