讨论 / 我很水?!!请来帮忙看看noip2010TG第一题,错在哪?
dyhys1 2013-07-11 02:03:00
点我顶贴 收藏 删除
测试结果,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.

谢谢大家!

#1 dyhys1@2011-08-10 19:21:00
回复 删除
RP++

RP+

#2 dyhys1@2011-08-10 23:44:00
回复 删除
DDD,

给力给力给力!

#3 wjcw@2013-07-11 02:03:00
回复 删除
回复 楼主dyhys1 的帖子

要初始化为 -1 ,这个测试点里有 0 !%>_<%

查看更多回复
提交回复