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 zjh777007 at 2008-10-31 23:20:49 on Problem 2698
In Reply To:在某个状态,取出下次访问时间最晚的元素,替换 Posted by:zymx at 2005-10-30 16:54:46
program pku2698;
var c,i,j,k,l,n,x,max,kk,s:longint;
    t,tf:boolean;
    a,DVD:array[0..1000] of longint;
begin
  readln(C);
  for i:=1 to C do begin
    readln(kk,n);
    s:=0;
    for j:=1 to kk do DVD[j]:=-1;
    for j:=1 to n do readln(a[j]);
    for j:=1 to n do begin
      t:=true;
      for k:=1 to kk do
        if DVD[k]=a[j] then begin t:=false; break; end;
      if t=false then continue;
      for k:=1 to kk do
        if DVD[k]=-1 then begin DVD[k]:=a[j]; s:=s+1; t:=false; break; end;
      if t=false then continue;

      for k:=1 to kk do begin
        tf:=true;
        for l:=j+1 to n do
          if a[l]=DVD[k] then tf:=false;
        if tf=true then begin DVD[k]:=a[j]; s:=s+1; t:=false; break; end;
      end;
      if t=false then continue;

      max:=0;
      for k:=1 to kk do begin
        for l:=j+1 to n do
          if a[l]=DVD[k] then begin
            if l>max then begin max:=l; x:=k; end;
            break;
          end;
      end;
      DVD[x]:=a[j]; s:=s+1;
    end;
    writeln(s);
  end;
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