记录编号 2592 评测结果 AAAAAAAAAA
题目名称 [NOIP 2007]Hanoi双塔问题 最终得分 100
用户昵称 Gravatar苏轼 是否通过 通过
代码语言 Pascal 运行时间 0.033 s
提交时间 2008-09-23 13:10:58 内存使用 0.31 MiB
显示代码纯文本
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;
 s3:string;
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);
 s3:='';
 for i:=1 to l do s3:=s3+chr(c[l-i+1]+48);
 add:=s3;
end;

function mul(s1,s2:string):string;
var
 a,b,c:array[1..300] of integer;
 i,j,l,l1,l2:integer;
 s3:string;
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);
 s3:='';
 for i:=2 to l do s3:=s3+chr(c[l-i+2]+48);
 mul:=s3;
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.