比赛 |
NOIP_5 |
评测结果 |
AAWWWWWWWA |
题目名称 |
行进方案 |
最终得分 |
30 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-24 20:33:10 |
显示代码纯文本
program cch(input,output);
var
f:array[0..1000] of string;
k,i:integer;
procedure swap(var s1,s2:string);
var
s3:string;
begin
s3:=s1;
s1:=s2;
s2:=s3;
end;
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;
function sub(s1,s2:string):string;
var
l1,l2,l,i:integer;
a,b,c:array[1..300] of integer;
s3:string;
begin
l1:=length(s1); l2:=length(s2);
if l1<l2 then begin write('-'); swap(s1,s2); end;
if l1=l2 then
if s1<s2 then begin write('-'); swap(s1,s2); end;
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 do c[i]:=0;
for i:=1 to l do
begin
if a[i]<b[i] then
begin
inc(a[i],10);
dec(a[i+1]);
end;
c[i]:=a[i]-b[i];
end;
while (l>1)and(c[l]=0) do dec(l);
s3:='';
for i:=1 to l do s3:=s3+chr(c[l-i+1]+48);
sub:=s3;
end;
begin
assign(input,'zbfa.in');
assign(output,'zbfa.out');
reset(input);
rewrite(output);
readln(k);
f[0]:='1'; f[1]:='3';
for i:=2 to k do
f[i]:=add(mul('2',sub(f[i-1],f[i-2])),mul('3',f[i-2]));
write(f[k]);
close(input);
close(output);
end.