就是一道凸包(枚举凸包的边作为矩形的一条边)的裸题,只是不太好打,所以犹豫到今天才打
不说了,说起AC都是泪啊,因为没有精度判断,没有判重(算距离时除0了)错了好久
拍了好久都和标称是一样的,因为我是随机生成数据,基本不可能有重复的点
代码请自动无视...193行pascal(都是一坨一坨的)
1 const 2 eps=1e-7; 3 var 4 x,y:array[0..50010]of extended; 5 s:array[0..50010]of longint; 6 p:array[0..50010,1..4]of longint; 7 n,tot:longint; 8 sp:extended; 9 10 procedure swap(var x,y:extended); 11 var 12 t:extended; 13 begin 14 t:=x;x:=y;y:=t; 15 end; 16 17 function min(x,y:extended):extended; 18 begin 19 if x<y then exit(x); 20 exit(y); 21 end; 22 23 function cj(x1,y1,x2,y2,x3,y3:extended):extended; 24 begin 25 exit((y1-y2)*(x3-x1)+(x2-x1)*(y3-y1)); 26 end; 27 28 function jl(x1,y1,x2,y2,x3,y3:extended):extended; 29 begin 30 exit(cj(x1,y1,x2,y2,x3,y3)/sqrt(sqr(x1-x2)+sqr(y1-y2))); 31 end; 32 33 procedure jiao(var x,y:extended;x1,y1,x2,y2,x3,y3:extended); 34 begin 35 x3:=x3-x1; 36 y3:=y3-y1; 37 if abs(x2)<eps then 38 begin 39 x:=x1; 40 y:=y1+y3; 41 exit; 42 end; 43 if abs(y2)<eps then 44 begin 45 x:=x1+x3; 46 y:=y1; 47 exit; 48 end; 49 x2:=y2/x2; 50 y3:=y3+x3/x2; 51 x3:=-1/x2; 52 x:=y3/(x2-x3); 53 y:=x*x2; 54 x:=x+x1; 55 y:=y+y1; 56 end; 57 58 procedure sort(l,r:longint); 59 var 60 i,j:longint; 61 xi,yi:extended; 62 begin 63 i:=l; 64 j:=r; 65 xi:=x[(l+r)>>1]; 66 yi:=y[(l+r)>>1]; 67 repeat 68 while (cj(x[0],y[0],xi,yi,x[i],y[i])<0)and(abs(cj(x[0],y[0],xi,yi,x[i],y[i]))>eps) do 69 inc(i); 70 while (cj(x[0],y[0],xi,yi,x[j],y[j])>0)and(abs(cj(x[0],y[0],xi,yi,x[j],y[j]))>eps) do 71 dec(j); 72 if i<=j then 73 begin 74 swap(x[i],x[j]); 75 swap(y[i],y[j]); 76 inc(i); 77 dec(j); 78 end; 79 until i>j; 80 if i<r then sort(i,r); 81 if j>l then sort(l,j); 82 end; 83 84 procedure init; 85 var 86 i:longint; 87 minx,miny:extended; 88 begin 89 read(n); 90 minx:=99999999999999999999999999999999999999; 91 miny:=99999999999999999999999999999999999999; 92 for i:=1 to n do 93 begin 94 read(x[i],y[i]); 95 if (y[i]<miny)or((abs(y[i]-miny)<eps)and(x[i]<minx)) then 96 begin 97 minx:=x[i]; 98 miny:=y[i]; 99 end; 100 end; 101 i:=1; 102 while i<=n do 103 if (abs(x[i]-minx)<eps)and(abs(y[i]-miny)<eps) then 104 begin 105 swap(x[i],x[n]); 106 swap(y[i],y[n]); 107 dec(n); 108 end 109 else inc(i); 110 x[0]:=minx; 111 y[0]:=miny; 112 sort(1,n); 113 inc(n); 114 x[n]:=x[0]; 115 y[n]:=y[0]; 116 end; 117 118 procedure work; 119 var 120 i:longint; 121 begin 122 for i:=1 to n do 123 begin 124 while (tot>0)and(cj(x[s[tot-1]],y[s[tot-1]],x[s[tot]],y[s[tot]],x[i],y[i])<0) do 125 dec(tot); 126 inc(tot); 127 s[tot]:=i; 128 if (abs(x[s[tot]]-x[s[tot-1]])<eps)and(abs(y[s[tot]]-y[s[tot-1]])<eps) then dec(tot); 129 end; 130 for i:=1 to tot do 131 begin 132 x[i]:=x[s[i]]; 133 y[i]:=y[s[i]]; 134 end; 135 n:=tot; 136 for i:=1 to n do 137 begin 138 if jl(-y[0],x[0],-y[1],x[1],x[i],y[i])<jl(-y[0],x[0],-y[1],x[1],x[p[0,2]],y[p[0,2]]) then p[0,2]:=i; 139 if jl(x[0],y[0],x[1],y[1],x[i],y[i])>jl(x[0],y[0],x[1],y[1],x[p[0,3]],y[p[0,3]]) then p[0,3]:=i; 140 if jl(-y[0],x[0],-y[1],x[1],x[i],y[i])>jl(-y[0],x[0],-y[1],x[1],x[p[0,4]],y[p[0,4]]) then p[0,4]:=i; 141 end; 142 for i:=1 to n-1 do 143 begin 144 p[i]:=p[i-1]; 145 p[i,1]:=i; 146 while jl(-y[i],x[i],-y[i+1],x[i+1],x[(p[i,2]+1)mod n],y[(p[i,2]+1)mod n])<jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,2]],y[p[i,2]]) do 147 p[i,2]:=(p[i,2]+1)mod n; 148 while jl(x[i],y[i],x[i+1],y[i+1],x[(p[i,3]+1)mod n],y[(p[i,3]+1)mod n])>jl(x[i],y[i],x[i+1],y[i+1],x[p[i,3]],y[p[i,3]]) do 149 p[i,3]:=(p[i,3]+1)mod n; 150 while jl(-y[i],x[i],-y[i+1],x[i+1],x[(p[i,4]+1)mod n],y[(p[i,4]+1)mod n])>jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,4]],y[p[i,4]]) do 151 p[i,4]:=(p[i,4]+1)mod n; 152 end; 153 sp:=99999999999999999999999999999999999999999999999999999; 154 for i:=0 to n-1 do 155 sp:=min(sp,abs((jl(x[i],y[i],x[i+1],y[i+1],x[p[i,1]],y[p[i,1]])-jl(x[i],y[i],x[i+1],y[i+1],x[p[i,3]],y[p[i,3]]))*(jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,2]],y[p[i,2]])-jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,4]],y[p[i,4]])))); 156 writeln(sp:0:5); 157 for i:=0 to n-1 do 158 if abs(abs((jl(x[i],y[i],x[i+1],y[i+1],x[p[i,1]],y[p[i,1]])-jl(x[i],y[i],x[i+1],y[i+1],x[p[i,3]],y[p[i,3]]))*(jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,2]],y[p[i,2]])-jl(-y[i],x[i],-y[i+1],x[i+1],x[p[i,4]],y[p[i,4]])))-sp)<eps then break; 159 jiao(x[n+1],y[n+1],x[i],y[i],x[i+1]-x[i],y[i+1]-y[i],x[p[i,2]],y[p[i,2]]); 160 jiao(x[n+2],y[n+2],x[p[i,2]],y[p[i,2]],y[i]-y[i+1],x[i+1]-x[i],x[p[i,3]],y[p[i,3]]); 161 jiao(x[n+3],y[n+3],x[p[i,3]],y[p[i,3]],x[i+1]-x[i],y[i+1]-y[i],x[p[i,4]],y[p[i,4]]); 162 jiao(x[n+4],y[n+4],x[p[i,4]],y[p[i,4]],y[i]-y[i+1],x[i+1]-x[i],x[i],y[i]); 163 x[0]:=999999999999999999999999999999999999999999; 164 y[0]:=999999999999999999999999999999999999999999; 165 for i:=1 to 4 do 166 if (y[n+i]<y[0])or((abs(y[0]-y[n+i])<eps)and(x[n+i]<x[0])) then 167 begin 168 x[0]:=x[n+i]; 169 y[0]:=y[n+i]; 170 end; 171 for i:=1 to 4 do 172 if (abs(x[0]-x[n+i])<eps)and(abs(y[0]-y[n+i])<eps) then break; 173 swap(x[n+4],x[n+i]); 174 swap(y[n+4],y[n+i]); 175 writeln(x[0]+eps:0:5,' ',y[0]+eps:0:5); 176 sort(n+1,n+3); 177 for i:=1 to 3 do 178 writeln(x[n+i]+eps:0:5,' ',y[n+i]+eps:0:5); 179 end; 180 181 begin 182 init; 183 work; 184 end.