|
|
back to boardWhy it doesn't work? (but passes all 2000-2001 real ACM test) - program inside Posted by Arkadiy 19 Nov 2001 16:49 type interv = record a,b:integer; end; var A:array[0..9999] of integer; IX,j,N,LX: integer; otvet: array[1..5001] of interv; num_otv: integer; no_curr_interval:boolean; t:integer; { g,f:text;} function BinarySearch(x:integer):integer; var p,q,i,L:integer; begin p:=0; q:=N-1; L:=0; while p<=q do begin i:=(p+q) div 2; inc(L); if A[i]=x then begin BinarySearch:=L; exit; end; if x<A[i] then q:=i-1 else p:=i+1; end; end; begin {assign(f,'in'); assign(g,'out'); reset(f); rewrite(g);} readln({f,}IX,LX); num_otv:=0; no_curr_interval:=true; for j:=0 to 9999 do A[j]:=j; for j:=0 to 9999 do begin N:=j+1; t:=BinarySearch(IX); if (t<>LX) and no_curr_interval then continue; if (t<>LX) then begin otvet[num_otv].b:=N-1; no_curr_interval:=true; continue; end; {t=LX} if not(no_curr_interval) then continue; no_curr_interval:=false; inc(num_otv); otvet[num_otv].a:=N; end; if not no_curr_interval then otvet[num_otv].b:=10000; writeln({g,}num_otv); for j:=1 to num_otv do begin writeln({g,}otvet[j].a,' ',otvet[j].b); end; { close(f); close(g);} end. Re: Why it doesn't work? (but passes all 2000-2001 real ACM test) - program inside Posted by Flyer 22 Nov 2001 20:15 Hi. Did you take part in that contest? Можно я по-русски буду? :) Мне кажется, что ты не учитываешь какой-то крайний случай... Моя программа тоже не идет :( Но ведь у других-то проходит. Кстати, ты будешь на этом полуфинале? Если да, то скажи в какой команде :) Re: Why it doesn't work? (but passes all 2000-2001 real ACM test) - program inside Because binarysearch doesnt return any valid value in case it doesnt find anything. You should add a line before end; of proc binarysearch something like binarysearch := 1000; (LX <= 14) Re: Why it doesn't work? (but passes all 2000-2001 real ACM test) - program inside Posted by Arkadiy 24 Nov 2001 21:41 I am captain of KubanState University, Krasnodar (KubanSU#1).. да на полуфинале я буду... завтра вылетаю с командой на самолете ;-) Подойди ко мне на соревновании, познакомимся... Thanks!!! Of course!!! Posted by Arkadiy 24 Nov 2001 22:03 Only binarysearch:=-1 before 'end;' needed!!! And all work fine!!! |
|
|