Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
今天郁闷了,这题都TLE,大牛帮忙优化一下……const fx:array[1..4] of integer=(0,0,-1,1); fy:array[1..4] of integer=(1,-1,0,0); type tr=array[1..3] of longint; var s:array[1..10000] of tr; f:array[1..10000] of longint; n,m,i,j,max:longint; procedure quicksort(lo,hi:integer); procedure sort(l,r:integer); var i,j:integer; x,y:tr; begin i:=l; j:=r; x:=s[(l+r) div 2]; repeat while s[i,1]<x[1] do i:=i+1; while x[1]<s[j,1] do j:=j-1; if i<=j then begin y:=s[i]; s[i]:=s[j]; s[j]:=y; i:=i+1; j:=j-1; end; until i>j; if l<j then Sort(l,j); if i<r then Sort(i,r); end; begin sort(lo,hi); end; function ok(a,b:integer):boolean; var f:boolean; i:integer; begin f:=false; for i:=1 to 4 do if (s[a,2]+fx[i]=s[b,2])and(s[a,3]+fy[i]=s[b,3]) then begin f:=true; break; end; ok:=f; end; begin while not seekeof do begin readln(n,m); for i:=1 to n do begin for j:=1 to m do begin read(s[(i-1)*m+j,1]); s[(i-1)*m+j,2]:=i; s[(i-1)*m+j,3]:=j; end; readln; end; quicksort(1,n*m); fillchar(f,sizeof(f),1); for i:=n*m downto 1 do begin max:=0; for j:=i+1 to n*m do if ok(i,j) then if f[j]>max then max:=f[j]; f[i]:=max+1; end; max:=0; for i:=1 to n*m do if f[i]>max then max:=f[i]; writeln(max); end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator