PKU 2007 Scrambled Polygon 极角排序

输入一个凸包且没有三点共线,输入的第一个点始终是(0,0),从(0,0)开始逆时针输出所有点。

因为只有三个象限有点,所以分象限极角排序输出即可。

var
  u,d1,d2,d3,d4,i,x,y:longint;
  s1,s2,s3,s4:array[0..50,1..2] of longint;

procedure work1;
var
  i,j:longint;
begin
  for i:=1 to d1-1 do
    for j:=i+1 to d1 do
      if s1[i,1]*s1[j,2]-s1[i,2]*s1[j,1]<0 then
      begin
        s1[0]:=s1[i];s1[i]:=s1[j];s1[j]:=s1[0];
      end;
  for i:=1 to d1 do
    writeln('(',s1[i,1],',',s1[i,2],')');
end;

procedure work2;
var
  i,j:longint;
begin
  for i:=1 to d2-1 do
    for j:=i+1 to d2 do
      if s2[i,1]*s2[j,2]-s2[i,2]*s2[j,1]<0 then
      begin
        s2[0]:=s2[i];s2[i]:=s2[j];s2[j]:=s2[0];
      end;
  for i:=1 to d2 do
    writeln('(',s2[i,1],',',s2[i,2],')');
end;

procedure work3;
var
  i,j:longint;
begin
  for i:=1 to d3-1 do
    for j:=i+1 to d3 do
      if s3[i,1]*s3[j,2]-s3[i,2]*s3[j,1]<0 then
      begin
        s3[0]:=s3[i];s3[i]:=s3[j];s3[j]:=s3[0];
      end;
  for i:=1 to d3 do
    writeln('(',s3[i,1],',',s3[i,2],')');
end;

procedure work4;
var
  i,j:longint;
begin
  for i:=1 to d4-1 do
    for j:=i+1 to d4 do
      if s4[i,1]*s4[j,2]-s4[i,2]*s4[j,1]<0 then
      begin
        s4[0]:=s4[i];s4[i]:=s4[j];s4[j]:=s4[0];
      end;
  for i:=1 to d4 do
    writeln('(',s4[i,1],',',s4[i,2],')');
end;

begin
  while not eof do 
  begin
    readln(x,y);
    if (x<>0)and(y<>0) then
      if (x>0)and(y>0)
        then begin
               inc(d1);
               s1[d1,1]:=x;
               s1[d1,2]:=y;
             end
        else if (x<0)and(y>0)
               then begin
                      inc(d2);
                      s2[d2,1]:=x;
                      s2[d2,2]:=y;
                    end
               else if (x<0)and(y<0)
                      then begin
                             inc(d3);
                             s3[d3,1]:=x;
                             s3[d3,2]:=y;
                           end
                      else begin
                             inc(d4);
                             s4[d4,1]:=x;
                             s4[d4,2]:=y;
                           end;
  end;
  if d1=0
    then u:=2
    else if d2=0
           then u:=3
           else if d3=0
                  then u:=4
                  else u:=1;
  writeln('(0,0)');
  for i:=1 to 3 do
  begin
    case u of
      1:work1;
      2:work2;
      3:work3;
      4:work4;
    end;
    u:=u mod 4+1;
  end;
end.


你可能感兴趣的:(PKU 2007 Scrambled Polygon 极角排序)