ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

Why WA 1 . HELP PLZ!!!
Posted by Darhan_Akzholov 8 Mar 2008 22:22
var tech : array [1..15000] of longint;
    pupil: array [1..1000000] of longint;
    i,m,n,kol:longint;
Procedure Find(k:longint);
Var l,r:longint;
begin
  l:=1;
  r:=m;
  while true do begin
    if k < pupil[(l+r) div 2] then
     begin
       if r=(l+r) div 2 then break;
       r:=(l+r) div 2;
     end
      else
    if k > pupil[(l+r) div 2] then
     begin
       if l=(l+r) div 2 then break;
       l:=(l+r) div 2;
     end
      else
    if k = pupil[(l+r) div 2] then begin inc(kol); l:=(l+r) div 2 + 1; end;
  end;
end;

Procedure Quick(l,r:longint);
Var i,j,k,q:longint;
begin
 i:=l; j:=r; k:=pupil[(l+r) div 2];
 repeat
   while pupil[i] < k do inc(i);
   while pupil[j] > k do dec(j);
   if i<=j then
    begin
      q:=pupil[i];
      pupil[i]:=pupil[j];
      pupil[j]:=q;
      inc(i);
      dec(j);
    end;
 until i>j;
 if r > i then Quick(i,r);
 if l < j then Quick(l,j);
end;

begin
 kol:=0;
 read(n);
 for i:=1 to n do read(tech[i]);
 read(m);
 for i:=1 to m do read(pupil[i]);
 Quick(1,m);
 for i:=1 to n do
  find(tech[i]);
 writeln(kol);
end.
Re: Why WA 1 . HELP PLZ!!!
Posted by lhmhl 21 Dec 2008 12:07
me too