不是VIP会员,不能显示答案

题目解答

题目:
var
data : array[1..20] of integer;
n,i,h,ans : integer;

procedure merge;
begin
data[h-1] := data[h-1] + data[h];
dec(h);
inc(ans);
end;

begin
readln(n);
h := 1;
data[h] := 1;
ans := 0;
for i:=2 to n do
begin
inc(h);
data[h] := 1;
while (h>1) and (data[h]=data[h-1]) do
merge;
end;
writeln(ans);
end.
(1)
输入:8
输出:______________ (5分)
(2)
输入:2016
输出:______________ (5分)

输出:7|2010
考点: 0
分析: 二进制
解答: f(1)=0
f(2)=2f(1)+1=1
f(4)=2f(2)+1=3
f(8)=2f(4)+1=7
f(16)=...16-1=15
...
f(1024)=1024-1=1023

f(10)=f(2)+f(8)=8

f(2016)=f(1024)+f(512)+f(256)+f(128)+f(64)+f(32)
=1023+511+255+127+63+31
=2010
评论:
老师: 0