比赛 |
07级noip练习1 |
评测结果 |
C |
题目名称 |
Hanoi双塔问题 |
最终得分 |
0 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-22 20:51:45 |
显示代码纯文本
program cch(input,output);
var
f:array[0..200] of string;
n,i:integer;
function add(s1,s2:string):string;
var
i,l,l1,l2:integer;
a,b,c:array[1..300] of integer;
begin
l1:=length(s1); l2:=length(s2);
for i:=1 to l1 do a[i]:=ord(s1[l1-i+1])-48;
for i:=1 to l2 do b[i]:=ord(s2[l2-i+1])-48;
if l1>l2 then
begin
l:=l1;
for i:=l2+1 to l do b[i]:=0;
end
else
begin
l:=l2;
for i:=l1+1 to l do a[i]:=0;
end;
for i:=1 to l+1 do c[i]:=0;
for i:=1 to l do
begin
c[i]:=c[i]+a[i]+b[i];
c[i+1]:=c[i] div 10;
c[i]:=c[i] mod 10;
end;
if c[l+1]<>0 then inc(l);
add:='';
for i:=1 to l do add:=add+chr(c[l-i+1]+48);
end;
function mul(s1,s2:string):string;
var
a,b,c:array[1..300] of integer;
i,j,l,l1,l2:integer;
begin
l1:=length(s1); l2:=length(s2);
for i:=1 to l1 do a[i]:=ord(s1[l1-i+1])-48;
for i:=1 to l2 do b[i]:=ord(s2[l2-i+1])-48;
l:=l1+l2+1;
for i:=1 to l do c[i]:=0;
for i:=1 to l1 do
for j:=1 to l2 do
c[i+j]:=c[i+j]+a[i]*b[j];
for i:=2 to l1+l2 do
begin
c[i+1]:=c[i+1]+c[i] div 10;
c[i]:=c[i] mod 10;
end;
while (l>2)and(c[l]=0) do dec(l);
mul:='';
for i:=2 to l do mul:=mul+chr(c[l-i+2]+48);
end;
begin
assign(input,'hanoi.in');
assign(output,'hanoi.out');
reset(input);
rewrite(output);
readln(n);
f[0]:='0';
for i:=1 to n do
f[i]:=add(mul('2',f[i-1]),'1');
write(mul(f[n],'2'));
close(input);
close(output);
end.