http://wikioi.com/training/?id=32
笔者终于受不了把解题报告写成教程的日子了,由于想写些交流思维的东西,笔者决定放弃Wikioi上普及一等之前的所(仅)有(剩)的题目,只在这里留下代码。
PS:其他等级的科普题也将省略详细的讲解……
Wikioi 天梯 二叉树最大宽度和高度(1501)
Program asd;
Var
n,i,a,b,maxdeep,maxwide:longint;
wide,deep:array[1..10000]of longint;
Begin
readln(n);
deep[1]:=1;
wide[1]:=1;
maxdeep:=1;
maxwide:=1;
for i:=1 to n do
begin
read(a,b);
if a<>0 then
begin
deep[a]:=deep[i]+1;
inc(wide[deep[a]]);
if deep[a]>maxdeep then maxdeep:=deep[a];
if wide[deep[a]]>maxwide then maxwide:=wide[deep[a]];
end;
if b<>0 then
begin
deep[b]:=deep[i]+1;
inc(wide[deep[b]]);
if deep[b]>maxdeep then maxdeep:=deep[b];
if wide[deep[b]]>maxwide then maxwide:=wide[deep[b]];
end;
end;
writeln(maxwide,' ',maxdeep);
End.
1842
Program asd;
Var
n,i:longint;
f:array[-30..1]of longint;
Begin
f[1]:=5;
f[0]:=5;
for i:=-1 downto -30 do
f[i]:=f[i+1]+f[i+2]+1;
readln(n);
if n>=0 then writeln(5)
else writeln(f[n]);
End.
3038
Program asd;
Var
n,i,a,tot:longint;
Begin
readln(n);
for i:=1 to n do
begin
read(a);
tot:=0;
while a<>1 do
begin
if odd(a) then a:=3*a+1
else a:=a div 2;
inc(tot);
end;
writeln(tot);
end;
End.
3143
Program asd;
Var
n,i,a,b:longint;
tree:array[1..20]of record
l,r:longint;
end;
Procedure qian(aa:longint);
begin
write(aa,' ');
if tree[aa].l<>0 then qian(tree[aa].l);
if tree[aa].r<>0 then qian(tree[aa].r);
end;
Procedure zhong(aa:longint);
begin
if tree[aa].l<>0 then zhong(tree[aa].l);
write(aa,' ');
if tree[aa].r<>0 then zhong(tree[aa].r);
end;
Procedure hou(aa:longint);
begin
if tree[aa].l<>0 then hou(tree[aa].l);
if tree[aa].r<>0 then hou(tree[aa].r);
write(aa,' ');
end;
Begin
readln(n);
for i:=1 to n do readln(tree[i].l,tree[i].r);
qian(1);
writeln;
zhong(1);
writeln;
hou(1);
End.
3145
Program asd;
Var
n:longint;
Procedure hanoi(aa:longint;cc,dd,ee:char);
begin
if aa=1 then
begin
writeln(1,' from ',cc,' to ',ee);
exit;
end;
hanoi(aa-1,cc,ee,dd);
writeln(aa,' from ',cc,' to ',ee);
hanoi(aa-1,dd,cc,ee);
end;
Begin
readln(n);
writeln(trunc(exp(ln(2)*n))-1);
hanoi(n,'A','B','C');
End.