测试结果,90分,<测试点9>未通过:正确答案297,我的输出为295...(奇怪)
我是这么想的,为节省空间,用一个1..100数组作为题目中的"内存",last作为指针,指向数组当前最后一个元素.
cir作为一个指针,初始为1.每替换一个单词,若cir<m,inc(cir)否则cir:=1(从头到尾循环).
怎么不行呢?望高手解答!!!
code如下:
program SNY_noip2010tg_01;
var
aa:array[1..100]of integer;
last,i,j,m,n,sn,x,cir:integer;
ok:boolean;
begin
readln(m,n);
last:=1;
sn:=0;
cir:=1;
for i:=1 to n do
begin
read(x);
ok:=true;
j:=1;
while ok and (j<=last) do
begin
if aa[j]=x then //check队列中是否已有单词
begin
ok:=false;
end;
inc(j);
end;
if ok then
if last<m then
begin
inc(sn);
inc(last); //队列未满
aa[last]:=x;
end
else
begin
inc(sn);
aa[cir]:=x;
if cir<m then
inc(cir)
else //用cir循环以指向目前队列中最早的元素
cir:=1;
end
end;
writeln(sn);
end.
谢谢大家!