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了type u=record k,a:longint; end; var s:array[0..50000] of u; t:array[0..50000,0..3] of longint; o,o2:array[0..50000] of longint; i,k,n:longint; procedure sort(l,r:longint); var i,j,w:longint; x,y:u; begin i:=l; j:=r; x:=s[(l+r) div 2]; repeat while s[i].a<x.a do i:=i+1; while x.a<s[j].a do j:=j-1; if i<=j then begin y:=s[i]; s[i]:=s[j]; s[j]:=y; w:=o[i]; o[i]:=o[j]; o[j]:=w; 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 readln(n); for i:=1 to n do begin readln(s[i].k,s[i].a); o[i]:=i; end; sort(1,n); for i:=1 to n do o2[o[i]]:=i; fillchar(t,sizeof(t),0); for i:=1 to n do t[i,0]:=s[i].k; for i:=2 to n do begin k:=1; while true do begin if s[i].k<t[k,0] then begin if t[k,2]=0 then begin t[k,2]:=i; t[i,1]:=k; break; end else k:=t[k,2]; end else begin if t[k,3]=0 then begin t[k,3]:=i; t[i,1]:=k; break; end else k:=t[k,3]; end; end; end; for i:=1 to n do writeln(o[t[o2[i],1]],' ',o[t[o2[i],2]],' ',o[t[o2[i],3]]); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator