|
|
back to boardLook at this AC one! Posted by mace 19 Nov 2002 20:15 This Program Got AC within 0.01 Sec! ---------------------------------------------------------------------- program answer1054; const st:array[0..1,0..2]of 1..3=((1,2,3),(1,3,2)); var d:array[1..31]of 1..3; e:array[1..31]of 0..1; n,i,s,f,delta,j,s1:longint; function mi2(x:integer):longint;{mi2=2^x} var s:longint; i:integer; begin s:=1; for i:=1 to x do s:=s*2; mi2:=s; end; function c(x:integer):longint;{N-dished Hanoi tower step uses} begin if x=31 then c:=maxlongint else c:=mi2(x)-1; end; begin readln(n); for i:=1 to n do read(d[i]); s:=0;f:=c(n); fillchar(e,sizeof(e),0); for i:=n downto 1 do begin s1:=1;delta:=0; for j:=i+1 to n do begin delta:=delta+e[j]*s1; s1:=s1*2; end; if d[i]=st[(n+i) mod 2,delta mod 3] then begin f:=f-mi2(i-1); end else if d[i]=st[(n+i) mod 2,(delta+1) mod 3] then begin s:=s+mi2(i-1); e[i]:=1; end else begin writeln(-1); halt; end; end; writeln(s); end. TOO long!!!it's only a simple mathematical problem.just 15 lines can finished. Re: Look at this AC one! It's too long |
|
|