分析:該題是經典的隊列題目,直接用隊列實作就可以。如果資料範圍大一些的話還可hash判重!
這可以說是一道送分的題目,但是還有粗心的學生會在這裡失分,主要原因是數組的範圍定義的不合适,因為空間足夠用,在考試中資料範圍要稍大一些。當然還有個别同學是因為模拟失誤了,這種送分題目我隻能說,一定要多對拍幾組特殊資料,保證得滿分才好!
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
轉載于:https://www.cnblogs.com/ssfzmfy/p/3983372.html