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 |
我的程序再次证明,这个算法没错!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator