2019春招笔试凉经-字节跳动20190316

 

1.求找钱最少给几个硬币

有1024元钱 输入你花掉的数目问找回的硬币数最小

有64 16 4 1 的硬币

res=1024-n
cnt=0
while res>=64:
    res-=64
    cnt+=1
while res>=16:
    res-=16
    cnt+=1
while res>=4:
    res-=4
    cnt+=1
while res>=1:
    res-=1
    cnt+=1
print(cnt)

2. 王大锤

在字符串中有连续的三个字母要去掉一个

有连续的AABB型的  要去掉第二对中的一个字母 即AAB

匹配顺序是从左到右例如AABBCC 结果为AABCC。

 

# 先遍历一遍,去掉连续三个及以上的连续相同字母,如AAAABBBCC变为AABBCC.

# 再遍历一遍,如果有AABB则变为AAB。


s=['helloo', 'woooooow','wwbbddggoxsanovoo']
for str1 in s:
    tmp=''
    for i in range(len(str1)):
        if i<len(str1)-2:
            if str1[i]==str1[i+1] and str1[i+1]==str1[i+2]:
                pass
            else:
                tmp+=str1[i]
        else:
            tmp+=str1[i]
    print(tmp)
    i=0
    while i<len(tmp)-3:
        if tmp[i]==tmp[i+1] and tmp[i+2]==tmp[i+3]:
            tmp=tmp[:i+3]+tmp[i+4:]
            i+=3
        else:
            i+=1
    print(tmp)

 

 

 

3.发奖品

 

###  还没跑出来。。等等填坑

4.  剪绳子

暴力二分

N=3
M=4
L=[3,5,4]
def isok(L, M, target):  # 输入数组L,可否分成target条长为M的绳子
    cnt=0
    for l in L:
        cnt+=l//target
    if cnt>=M:
        return True
    else:
        return False

left=0
right=1e9
eps=1e-5   # 如果区间几乎不再收缩了,就可以跳出while
while left<right-eps:
    mid=(right+left)/2.0
    if isok(L,M,mid):
        left=mid
    else:
        right=mid
print('%3.2f'%round(left,2))  # 四舍五入 输出两位小数

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值