讨论 / 测试结果90分..唯独测试点9不通过..求指正!
dyhys1 2011-08-10 18:41:00
点我顶贴 收藏 删除
请来帮忙看看 noip2010TG第一题,错在哪?

测试结果,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.

谢谢大家!

查看更多回复
提交回复