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

谁能帮帮我呀 怎么一直 wa

Posted by yeshuxiong at 2005-07-06 16:13:24 on Problem 1968
var
 f,s:array [1..3000] of longint;

 procedure run(h,t:longint);
 var
  tmp,mid,i,j,ms:longint;
 begin
  i:=h;j:=t;
  mid:=f[(h+t) div 2];ms:=s[(h+t) div 2];
  while (i<=j) do
   begin
    while (f[i]<mid) or ((f[i]=mid)and(s[i]<ms)) do inc(i);
    while (mid<f[j]) or ((f[j]=mid)and(s[j]>ms)) do dec(j);
    if i<=j then
     begin
      tmp:=f[i];f[i]:=f[j];f[j]:=tmp;
      tmp:=s[i];s[i]:=s[j];s[j]:=tmp;
      inc(i);dec(j);
     end;
   end;
  if h<j then run(h,j);
  if i<t then run(i,t);
 end;

 procedure main;
 var
  n,m,k,i,j,l:longint;
 begin
  readln(m);
  readln(k);
  readln(n);
  for i:=1 to n do
   begin
    read(f[i]);s[i]:=i;
   end;readln;
  run(1,n);
  i:=0;
  while i<n do
   begin
    inc(i);
    while (i+1<=n) and (f[i]=f[i+1]) do
     begin
      inc(i);
      s[i]:=s[i-1];
     end;
   end;
  l:=n-abs(n div m)*(k+1);
  if k+1>l then k:=abs(n div m)*k+l else k:=abs(n div m)*k+k+1;
  k:=k+1;
  l:=k;
  for i:=k to n do
   if s[l]>s[i] then l:=i;
  writeln(f[l]);
 end;

begin
 while not eof do main;
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