Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题

Posted by jinzhihan at 2014-04-17 20:20:55 on Problem 2388
var
  a:array[1..100000] of longint;
  n,i:longint;

procedure sort(l,r:longint);
var
  i,j,t,x:longint;
begin
  i:=l; j:=r; x:=a[(l+r) div 2];
  repeat
    while a[i]<x do inc(i);
    while a[j]>x do dec(j);
    if not(i>j)
      then
        begin
          t:=a[i]; a[i]:=a[j]; a[j]:=t;
          inc(i); dec(j);
        end;
  until i>j;
  if l<j then sort(l,j);
  if r>i then sort(i,r);
end;

begin
  readln(n);
  for i:=1 to n do readln(a[i]);

  sort(1,n);

  writeln(a[(1+n) div 2]);
end.


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator