科大讯飞C++方向两道AC代码(python)
作者:ukulele201903082324789
链接:https://www.nowcoder.com/discuss/225495?type=post&order=time&pos=&page=1&subType=1
来源:牛客网
1.割木棍:
n = int(input())
ret = 0
if n == 2:
print(1)
elif n == 3:
print(2)
else:
for i in range(0,100):
for j in range(0,100):
if i*2 + j*3 == n and ret < (2**i)*(3**j):
ret = (2**i)*(3**j)
print(ret)
2.二分查找
n = int(input())
a = list(map(int,input().split()))
b = int(input())
L = 0
R = n-1
ret = -1
while L <= R:
mid = (L + R) //2
if a[mid] >= b:
ret = mid
R = mid - 1
else:
L = mid + 1
if ret == -1 or a[ret] != b:
print(-1)
else:
print(ret)
作者:ukulele201903082324789
链接:https://www.nowcoder.com/discuss/225495?type=post&order=time&pos=&page=1&subType=1
来源:牛客网
1.割木棍:
n = int(input())
ret = 0
if n == 2:
print(1)
elif n == 3:
print(2)
else:
for i in range(0,100):
for j in range(0,100):
if i*2 + j*3 == n and ret < (2**i)*(3**j):
ret = (2**i)*(3**j)
print(ret)
2.二分查找
n = int(input())
a = list(map(int,input().split()))
b = int(input())
L = 0
R = n-1
ret = -1
while L <= R:
mid = (L + R) //2
if a[mid] >= b:
ret = mid
R = mid - 1
else:
L = mid + 1
if ret == -1 or a[ret] != b:
print(-1)
else:
print(ret)
全部评论
相关推荐
查看21道真题和解析 点赞 评论 收藏
分享
04-15 17:16
安徽工业大学 IT技术支持 在下uptown:本质上是因为我们的苦难教育,从小只引导闷头学,上台说个话腿都得哆嗦,看见女孩心跳的喘不过来气,到了大学里没人告诉你怎么转变心态
点赞 评论 收藏
分享