ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1116. Piecewise Constant Function

Can someone look at this?
Posted by Crytcheck 27 Apr 2002 17:14
Hi,
i've got a little bit diffrent alg. than 'normal' one. array[-
32000..32000], where i mark begining and ends of interval. than just
searching all table and write the output. i can't find any test,
where my prog. doesn't work, but i still have wrong answer. here's my
code:


type twartosc=record
       val:shortint;
       p1,p2,k1,k2:boolean;
     end;

var tab:array[-32000..32000] of twartosc;
    n,p,i,k,w,j:integer;
    o1,o2:boolean; {is F1 and F2 definned with given argument?)


begin
  read(n);
if n=0 then begin write(0); exit; end;
  for i:=1 to n do
    begin
      read(p);
      read(k);
      read(w);
      for j:=p to k do tab[j].val:=w;
      tab[p].p1:=true;
      tab[k].k1:=true; {reading F1 and mark it in array}
    end;
  readln;
  read(n);
if n<>0 then
  for i:=1 to n do
    begin
      read(p);
      read(k);
      read(w);
      tab[p].p2:=true;
      tab[k].k2:=true; {the same with F2 (it's value isn't nedded)}
    end;

  j:=0; {let j tell us about number of intervals of output function}
  for i:=-32000 to 32000 do
    begin
      if (tab[i].k1) then o1:=false; {close F1}
      if (tab[i].p2) then o2:=true;  {open F2}
      if tab[i].k2 then
        begin
          if o1 then inc(j); {if F1 is opened and we're closing F2,
new interval is begging}
          o2:=false;
        end;
      if tab[i].p1 then
        begin
          if not o2 then inc(j); {similar to prev}
          o1:=true;
        end;
    end;

  write(j,' '); {write number of intervals, and now we're seeking for
them}
  for i:=-32000 to 32000 do
    begin
      if (tab[i].k1) then
        begin
          o1:=false;
          if not o2 then write(i,' ',tab[i].val,' ');
        end;
      if (tab[i].p2) then
        begin
          o2:=true;
          if (o1) and (not tab[i].k2) then write(i,' ',tab
[i].val,' ');
        end;
      if tab[i].k2 then
        begin
          if (o1) and (not tab[i].p2) then write(i,' ');
          o2:=false;
        end;
      if tab[i].p1 then
        begin
          if not o2 then write(i,' ');;
          o1:=true;
        end;
    end;
end.