Loading

处女座的砝码

链接:https://ac.nowcoder.com/acm/contest/327/C
来源:牛客网

处女座热爱做物理实验,为了实验,处女座必须要精确的知道物品的质量。处女座准备自己设计一套砝码,每一个砝码都是正整数,这套砝码必须能够精确测量出n以内所有正整数的质量,处女座想要知道至少需要多少个砝码。你可以在天平的任意一边放置砝码。

 

思路:

比如:你输入20,输出答案是4,下面是各个数字的组合:

你可以选择1,2,6,11
1=1        <
2=2   <
3=1+2
4=6-2
5=6-1
6=6   <
7=6+1
8=6+2
9=6+2+1
10=11-1
11=11  <
12=11+1
13=11+2
14=11+2+1
15=11+6-2
16=11+6-1
17=11+6
18=11+6+1
19=11+6+2
20=11+6+2+1

import math
n=int(imput())
n=math.log(n*2+1,3)
if (n-int(n)>0):
    n+=1;
print(int(n))

 

posted @ 2019-01-29 19:48  青山新雨  阅读(288)  评论(0编辑  收藏  举报