京东算法笔试求交流

1.股票,求最小损失。时间超时,27%
n,m = list(map(int,input().strip().split()))
readarr = list(map(int,input().strip().split()))[:n]
num = int(input().strip())
readarr.sort()
try:
    for j in range(num):
        choose = int(input().strip())
        arr = readarr[:choose][::-1]
        sum = 0
        for i in range(len(arr)):
            sum += ((i // m) + 1) * arr[i]
        print(str(int(sum)))
except:
    pass
2.求点组成的平行线段个数。通过67%,感觉自己题意理解的有点问题
#!/bin/python
# -*- coding: utf8 -*-
import sys
import os
import re


def fun(n):
    temp = []
    re = {}
    re['inf']=0
    for i in range(n):
        x, y = list(map(int, input().strip().split()))[:2]
        if len(temp)==0:
            temp.append([x,y])
        else:
            for tem in temp:
                if (tem[0]-x)==0:
                    re['inf'] += 1
                elif (tem[1]-y)/(tem[0]-x) not in re:
                    re[(tem[1]-y)/(tem[0]-x)] = 1
                else:
                    re[(tem[1] - y) / (tem[0] - x)] += 1
            temp.append([x, y])
    count = 0
    m = 0
    for k,v in re.items():
        if v>m:
            m = v
    print((m)*(m-1)//2)

if __name__=="__main__":
    n = int(input().strip())
    fun(n)




#京东笔试##京东##笔试题目#
全部评论
第二题呢
点赞 回复 分享
发布于 2020-04-18 21:38
股票我也27、、
点赞 回复 分享
发布于 2020-04-18 21:06
第一题心态爆炸,怎么算都是27
点赞 回复 分享
发布于 2020-04-18 21:01

相关推荐

不愿透露姓名的神秘牛友
07-09 13:05
TMD找工作本来就烦,这东西什么素质啊😡
Beeee0927:hr是超雄了,不过也是有道理的
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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