const zero=1e-6; maxn=100000; type point=record x,y:extended; end; var p:array[1..maxn]of point; ch:array[1..maxn]of longint; temp,n,m,i,j,k:longint; function sgn(x:extended):longint; inline; begin if abs(x)<zero then exit(0); if x<0 then sgn:=-1 else sgn:=1; end; function cross(a,b,c:point):extended; inline; begin cross:=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x); end; function dist(a,b:point):extended; inline; begin dist:=sqr(a.x-b.x)+sqr(a.y-b.y); end; function cmp(a,b,c:point):boolean; inline; var temp:longint; begin temp:=sgn(cross(a,b,c)); if temp<>0 then exit(temp<0); {*B} cmp:=dist(a,b)<dist(a,c); {*A} end; begin assign(input,'Hull.in'); reset(input); assign(output,'Hull1.out'); rewrite(output); readln(n); for i:=1 to n do begin readln(p[i].x,p[i].y); if (j=0)or(p[i].x<p[j].x)or (sgn(p[i].x-p[j].x)=0)and(p[i].y<p[j].y) then j:=i; end; temp:=j; while true do begin k:=0; inc(m); ch[m]:=j; for i:=1 to n do if (i<>j)and((k=0)or cmp(p[j],p[k],p[i])) then k:=i; if k=temp then break; j:=k; end; for i:=1 to m do writeln(p[ch[i]].x:0:2,' ',p[ch[i]].y:0:2); close(input); close(output); end.
凸包。
http://blog.sina.com.cn/s/blog_9dff1a750101ag0l.html
猜你喜欢
转载自1260535207.iteye.com/blog/2291647
今日推荐
周排行