牛客编程巅峰赛S2第1场 - 青铜&白银&黄金题解

最小差值

https://ac.nowcoder.com/acm/contest/9004/A

链接:https://ac.nowcoder.com/acm/contest/9004/A
最小差值:
排序+贪心

class Solution:
    def minDifference(self , a ):
        # write code here
        a = sorted(a)
        minDif = float("inf")
        for i in range(len(a) - 1):
            minDif = min(a[i+1] - a[i], minDif)
        return minDif

Tree IV:
分层求和,python对小数取模好像有坑,具体在哪不太清楚。然后要先除以2在取模要不然会丢失精度。
链接:https://ac.nowcoder.com/acm/contest/9004/B
来源:牛客网

        mod = 998244353
        total = 0
        left = 1
        dep = 1
        while left <= n:
            right = min(2*left - 1, n)
            total = (total + (dep * ((left + right) * (right - left + 1) // 2) % mod) % mod) % mod
            left = right + 1
            dep += 1
        return total % mod

链接:https://ac.nowcoder.com/acm/contest/9004/C
来源:牛客网
牛牛组数:
排序+贪心

class Solution:
    def Maxsumforknumers(self , x , k ):
        # write code here
        x = sorted(x, reverse=True)
        total = 0
        maxlen = len(x) - k + 1
        total += int("".join(x[:maxlen]))
        for i in range(maxlen, len(x)):
            total += int(x[i])
        return total
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:02
ssob上原来真有BOSS啊
硫蛋蛋:这种也是打工的,只不是是给写字楼房东打工
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
哈哈哈哈哈哈哈哈哈哈这个世界太美好了
凉风落木楚山秋:毕业出路老师不管,你盖个章他好交差就完事了,等你盖完毕业了就不关他事情了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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