第三次模拟考-大数据方向-编程题

#1 数组变换
#思路:即数组中的每个数都除2,直至不能整除,判断剩下的数是否为同一个
# -*-- coding:utf-8 -*-
import sys

if __name__ == '__main__':
    while 1:
        t = sys.stdin.readline().strip()
        if not t:
            break
        t = int(t)
        nums = [int(i) for i in sys.stdin.readline().strip().split(' ')]
        for i in xrange(t):
            while nums[i]%2==0:
                nums[i] /=2

        numSet = set(nums)
        if len(numSet) ==1:
            print "YES"
        else:
            print "NO"
#2 排序字序列
#思路:题目意思,判断数组中 严格递增字序列,非严格递增字序列、严格递减字序列、非严格递减字序列
#  取了一个巧,把数组中相邻的数字重复的进行去重,然后寻找严格递增字序列和严格递减字序列就可以了  # -*-- coding:utf-8 -*-
import sys


def getUp(numsO, ind,lens):

    while ind+1<lens:
        if numsO[ind+1]>numsO[ind]:
            ind+=1
        else:
            return ind+1
    return -1


def getDown(numsO, ind, lens):

    while ind + 1 < lens:
        if numsO[ind + 1] < numsO[ind]:
            ind += 1
        else:
            return ind + 1
    return -1


if __name__ == '__main__':
    while 1:
        t = sys.stdin.readline().strip()
        if not t:
            break
        t = int(t)
        nums = [int(i) for i in sys.stdin.readline().strip().split(' ')]
        if t <= 2:
            print 1
            continue
        numsO=[nums[0]]
        for i in xrange(1,t):
            if nums[i]!=nums[i-1]:
                numsO.append(nums[i])
        res=0
        lens = len(numsO)
        if lens==1:
            print 1
            continue
        ind = 0
        while ind+1 < lens:
            if numsO[ind+1]>numsO[ind]:
                ind = getUp(numsO,ind,lens)
                res+=1
                if ind==-1:
                    break
            else:
                ind = getDown(numsO,ind,lens)
                res += 1
                if ind == -1:
                    break
            if ind==lens-1:
                res+=1
        print res

#3 :牛牛的序列
#思路:跟上一题类似,把数组划分成不同的递增字序列,若存在字序列a,b , 即:
###   1) 判断能否改变a的最大的能不能和b进行合并
###   2) 判断能否改变b的最小的能不能和a进行合并
# -*-- coding:utf-8 -*-
import sys

if __name__ == '__main__':
    while 1:
        t = sys.stdin.readline().strip()
        if not t:
            break
        t = long(t)
        nums = [long(i) for i in sys.stdin.readline().strip().split(' ')]
        res= []
        mins=0
        maxs=0
        for i in xrange(1,t):
            if nums[i]>nums[i-1]:
                maxs = i
            else:
                res.append((mins,maxs))
                mins=i
                maxs=i
        res.append((mins,maxs))
        lens = len(res)-1
        ans =-1
        for ind in xrange(lens):
            minInd = res[ind][1]
            maxInd = res[ind+1][0]
            if minInd - 1 <0 and nums[maxInd]>=2:
                ans = max(ans,1+res[ind+1][1])
                continue
            if res[ind][0] == res[ind][1] or res[ind+1][0]==res[ind+1][1]:
                ans = max(ans,res[ind][1]-res[ind][0]+1+res[ind+1][1]-res[ind+1][0]+1)
                continue
            if nums[maxInd]-nums[minInd-1]>=2 or nums[maxInd+1]-nums[minInd]>=2:
                ans = max(ans,res[ind][1]-res[ind][0]+1+res[ind+1][1]-res[ind+1][0]+1)

        print ans

全部评论
大牛啊,受益匪浅!!get~
点赞 回复 分享
发布于 2017-05-19 21:19

相关推荐

牛客51274894...:照片认真的吗,找个专门拍证件照的几十块钱整端正点吧,要不就别加照片
点赞 评论 收藏
分享
刚刷到字节跳动官方发的消息,确实被这波阵仗吓了一跳。在大家还在纠结今年行情是不是又“寒冬”的时候,字节直接甩出了史上规模最大的转正实习计划——ByteIntern。咱们直接看几个最硬的数,别被花里胡哨的宣传词绕晕了。首先是“量大”。全球招7000多人是什么概念?这几乎是把很多中型互联网公司的总人数都给招进来了。最关键的是,这次的资源分配非常精准:研发岗给了4800多个Offer,占比直接超过六成。说白了,字节今年还是要死磕技术,尤其是产品和AI领域,这对于咱们写代码的同学来说,绝对是今年最厚的一块肥肉。其次是大家最关心的“转正率”。官方直接白纸黑字写了:整体转正率超过50%。这意味着只要你进去了,不划水、正常干,每两个人里就有一个能直接拿校招Offer。对于2027届(2026年9月到2027年8月毕业)的同学来说,这不仅是实习,这简直就是通往大厂的快捷通道。不过,我也得泼盆冷水。坑位多,不代表门槛低。字节的实习面试出了名的爱考算法和工程实操,尤其是今年重点倾斜AI方向,如果你简历里有和AI相关的项目,优势还是有的。而且,转正率50%也意味着剩下那50%的人是陪跑的,进去之后的考核压力肯定不小。一句话总结:&nbsp;27届的兄弟们,别犹豫了。今年字节这是铁了心要抢提前批的人才,现在投递就是占坑。与其等到明年秋招去千军万马挤独木桥,不如现在进去先占个工位,把转正名额攥在手里。
喵_coding:别逗了 50%转正率 仔细想想 就是转正与不转正
字节7000实习来了,你...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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