[bzoj1069]最大土地面积

扫一遍凸包,然后卡一圈壳。

(pascal好玄)

  1 type Point=record
  2     x,y:Real;
  3 end;
  4 var i,j,n,top,his,p1,p2:longint;
  5     p,stack:array[0..10010] of Point;
  6     ans:Real;
  7 
  8 function max(a,b:Real): Real;inline;
  9 begin
 10     if a<b then max:=b
 11     else max:=a;
 12 end;
 13 
 14 operator < (a,b:Point)ret:Boolean;inline;
 15 begin
 16     if a.x=b.x then ret:=a.y<b.y
 17     else ret:=a.x<b.x;
 18 end;
 19 
 20 operator * (a,b:Point)ret:Real;inline;
 21 begin
 22     ret:=a.x*b.y-a.y*b.x;
 23 end;
 24 
 25 operator - (a,b:Point)ret:Point;inline;
 26 var pt:Point;
 27 begin
 28     pt.x:=a.x-b.x;
 29     pt.y:=a.y-b.y;
 30     ret:=pt;
 31 end;
 32 
 33 procedure sort(l,r:longint);inline;
 34 var i,j:longint;
 35     x,y:Point;
 36 begin
 37     i:=l;j:=r;
 38     x:=p[(l+r) div 2];
 39     repeat
 40         while p[i]<x do inc(i);
 41         while x<p[j] do dec(j);
 42         if i<=j then
 43         begin
 44             y:=p[i];
 45             p[i]:=p[j];
 46             p[j]:=y;
 47             inc(i);dec(j);
 48         end;
 49     until i>j;
 50     if i<r then sort(i,r);
 51     if l<j then sort(l,j);
 52 end;
 53 
 54 procedure add(a:Point;bot:longint);inline;
 55 begin
 56     while (top<>bot) and ((a-stack[top-1])*(stack[top]-stack[top-1])>=0) do dec(top);
 57     inc(top);
 58     stack[top]:=a;
 59 end;
 60 
 61 begin
 62     ans:=0;
 63     readln(n);
 64     i:=1;
 65     while i<=n do 
 66     begin
 67         readln(p[i].x,p[i].y);
 68         inc(i);
 69     end;
 70     sort(1,n);
 71     top:=1;
 72     stack[top]:=p[1];
 73     i:=2;
 74     while i<=n do
 75     begin
 76         add(p[i],1);
 77         inc(i);
 78     end;
 79     his:=top;
 80     i:=n-1;
 81     while i>=1 do
 82     begin
 83         add(p[i],his);
 84         dec(i);
 85     end;
 86     dec(top);
 87     stack[0]:=stack[top];
 88     i:=0;
 89     while i<top do
 90     begin
 91         p1:=1;
 92         p2:=1;
 93         j:=i+1;
 94         while j<top do
 95         begin
 96             while ((stack[p1+1]-stack[i])*(stack[j]-stack[i]))>((stack[p1]-stack[i])*(stack[j]-stack[i])) do p1:=(p1+1) mod top;
 97             while ((stack[j]-stack[i])*(stack[p2+1]-stack[i]))>((stack[j]-stack[i])*(stack[p2]-stack[i])) do p2:=(p2+1) mod top;
 98             ans:=max(ans,((stack[p1]-stack[i])*(stack[j]-stack[i]))+((stack[j]-stack[i])*(stack[p2]-stack[i])));
 99             inc(j);
100         end;
101         inc(i);
102     end;
103     writeln((ans/2.0):0:3);
104 end.
View Code

 

posted @ 2017-01-31 20:53  KingSann  阅读(84)  评论(0)    收藏  举报