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 1028. Stars

I insist... why am i getting wrong answer?
Posted by Costel::icerapper@k.ro 6 Mar 2002 02:39
program timus_1028;
const
  maxn=15000;
type
  tcoord=record x,y:longint end;

function Greater(c1,c2:tcoord):boolean;
begin
  Greater:=(c1.x+c1.y)>(c2.x+c2.y);
end;

type
  ta=array[1..maxn]of tcoord;
  tv=array[0..maxn]of word;
var
  n:longint;
  a:ta;
  v:tv;

procedure read_data;
var
  i:longint;
begin
  readln(n);
  for i:=1 to n do
    readln(a[i].x,a[i].y);
end;

procedure Switch(var a,b:tcoord);
var
  c:tcoord;
begin
  c:=a;
  a:=b;
  b:=c;
end;

procedure quicky(start,stop:longint);
var
 ini,fin:longint;
 step:longint;
begin
  if start>=stop then
    exit;
  ini:=start; fin:=stop; step:=1;
  while ini<fin do
  begin
    if Greater(a[ini],a[fin]) then
    begin
      Switch(a[ini],a[fin]);
      step:=1-step;
    end;
    inc(ini,step); dec(fin,1-step);
  end;
  quicky(start,ini-1);
  quicky(fin+1,stop);
end;

procedure sort_data;
begin
  quicky(1,n);
end;

procedure init_data;
begin
  fillchar(v,sizeof(v),0);
end;

procedure make_data;
var
  i:longint;
  k:longint;
begin
  v[0]:=1;k:=0;
  for i:=2 to n do
  begin
    if Greater(a[i],a[i-1]) then
      inc(k);
    inc(v[k]);
  end;
end;

procedure writ_data;
var
  i:longint;
begin
  for i:=0 to n-1 do
    writeln(v[i]);
end;

begin
  read_data;
  sort_data;
  init_data;
  make_data;
  writ_data;
end.
Re: I insist... why am i getting wrong answer?
Posted by malandro 28 May 2002 01:39
I am working in this problem (1028) and had the same mistake ... You
firt of all don't have to sort the list of stars ... There can be
only one star at one point of the plane. Stars are listed in
ascending order of Y coordinate. Stars with equal Y coordinates are
listed in ascending order of X coordinate. So you have only to check
if a star is greater then other ... here is my program,  I'm having
some throublems with the  time limit:

program star;

type
testrela   = record
   X,Y,index: Integer;
end;

var
  constelacao :array [0..1499] of Testrela;
  n,i: integer;
  respostas :  array [0..1499] of integer;

procedure PchecaStatus(ponteiro:integer);
 var i: integer;

 begin
  for i:=(ponteiro-1) downto 0 do
   if (constelacao[ponteiro].x>=constelacao[i].x) then
    begin
     if constelacao[i].index= i then
      begin
       constelacao[ponteiro].index:= constelacao
[ponteiro].index+constelacao[i].index+1;
       exit;
      end
     else
       inc(constelacao[ponteiro].index);
    end;
 end;

begin
 readln(n);
 readln(constelacao[0].x,constelacao[0].y);
 constelacao[0].index:=0;
 respostas[0]:=1;

 for i:=1 to (n-1) do
  begin
   readln(constelacao[i].x,constelacao[i].y);
   constelacao[i].index:=0;
   PchecaStatus(i);
   inc(respostas[constelacao[i].index]);
  end;

 for i:=0 to (n-1) do
   writeln(respostas[i]);
end.

I hope i could help you any way ... And i'll be thankfull if you
could give me some help..
[]'s

Re: I insist... why am i getting wrong answer?
Posted by malandro 28 May 2002 01:39
I am working in this problem (1028) and had the same mistake ... You
firt of all don't have to sort the list of stars ... There can be
only one star at one point of the plane. Stars are listed in
ascending order of Y coordinate. Stars with equal Y coordinates are
listed in ascending order of X coordinate. So you have only to check
if a star is greater then other ... here is my program,  I'm having
some throublems with the  time limit:

program star;

type
testrela   = record
   X,Y,index: Integer;
end;

var
  constelacao :array [0..14999] of Testrela;
  n,i: integer;
  respostas :  array [0..14999] of integer;

procedure PchecaStatus(ponteiro:integer);
 var i: integer;

 begin
  for i:=(ponteiro-1) downto 0 do
   if (constelacao[ponteiro].x>=constelacao[i].x) then
    begin
     if constelacao[i].index= i then
      begin
       constelacao[ponteiro].index:= constelacao
[ponteiro].index+constelacao[i].index+1;
       exit;
      end
     else
       inc(constelacao[ponteiro].index);
    end;
 end;

begin
 readln(n);
 readln(constelacao[0].x,constelacao[0].y);
 constelacao[0].index:=0;
 respostas[0]:=1;

 for i:=1 to (n-1) do
  begin
   readln(constelacao[i].x,constelacao[i].y);
   constelacao[i].index:=0;
   PchecaStatus(i);
   inc(respostas[constelacao[i].index]);
  end;

 for i:=0 to (n-1) do
   writeln(respostas[i]);
end.

I hope i could help you any way ... And i'll be thankfull if you
could give me some help..
[]'s