| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第一次做计算几何,三点一线也判断了,用叉积做的,怎么就不过呢????program poj1696;
type
data=record
x,y,num:longint;
end;
var
zk:array[0..50]of integer;
ck:array[1..50]of boolean;
a:array[0..50]of data;
i,j,k,l,m,sum,n:longint;
bg,tmp:data;
function check(p1,p2,p3:data):boolean;
var
x1,x2,y1,y2,d:longint;
begin
x1:=(p3.x-p1.x);
x2:=(p2.x-p1.x);
y1:=(p3.y-p1.y);
y2:=(p2.y-p1.y);
d:=x1*y2-y1*x2;
if d<0 then exit(true)
else if d>0 then exit(false)
else begin
if abs(x1)<abs(x2) then exit(false)
else exit(true);
end;
end;
procedure qsort(l,r:longint;p:data);
var
i,j,min:longint;
mid,tmp:data;
begin
for i:=l to r-1 do
begin
min:=i;
for j:=i+1 to r do
if check(p,a[j],a[min]) then min:=j;
if min<>i then begin
tmp:=a[i];
a[i]:=a[min];
a[min]:=tmp;
end;
end;
end;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
begin
assign(input,'test.in'); reset(input);
readln(k);
a[0].x:=1;
a[0].y:=0;
for l:=1 to k do begin
bg.y:=maxlongint;
sum:=0;
readln(n);
for i:=1 to n do begin
readln(a[i].num,a[i].x,a[i].y);
bg.y:=min(bg.y,a[i].y);
end;
bg.x:=0;
while sum<n do
begin
qsort(1,n-sum,bg);
i:=1;
inc(sum);
zk[sum]:=a[i].num;
ck[a[i].num]:=true;
bg:=a[i];
a[i]:=a[n-sum+1];
end;
write(n);
for i:=1 to n do write(' ',zk[i]);
writeln;
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator