Analysis: this is a classic queue question, which can be implemented directly using the queue. If the data range is larger, hash can be used to determine the weight!
This can be said to be a score delivery question, but some careless students may lose points here. The main reason is that the range definition of the array is inappropriate because the space is sufficient, the data range during the exam is slightly larger. Of course, there are still some students who make mistakes in the simulation. I can only say that we must have a few more pairs of special data to ensure a full score!
var m,n,sum:longint; q:array[0..1000] of longint; head,tail:longint; procedure init; var bo:boolean; i,j,x:longint; begin readln(m,n); head:=0;tail:=0; sum:=0; for i:=1 to n do begin bo:=false; read(x); for j:=head+1 to tail do if q[j]=x then begin bo:=true; break; end; if not bo then begin if tail-head>=M then inc(head); inc(tail); q[tail]:=x;inc(sum); end end; writeln(sum); end;begin assign(input,‘translate.in‘);reset(input); assign(output,‘translate.out‘); rewrite(output); init; close(input); close(output);end.
View code
Machine Translation (noip2010)