一遇到数学题和计算几何题我就要调半天……
玛雅,我真是太弱了……
基本思路很简单,先上凸包,然后矩形与凸包一边重合,然后旋转卡壳即可
然而我没怎么写过计算几何题,一开始写的各种囧,后来看了hzwer的写法才写得正常一些
一开始写囧,是找矩形的左右边界,用勾股定理算的,囧得不行;
后来发现可以用点积来判断,点积的几何意义:向量A在向量B上投影的长度*向量B的长度
然后就很好做了
1 const eps=1e-8; 2 type point=record 3 x,y:double; 4 end; 5 6 var a:array[0..50010] of point; 7 q:array[0..50010] of longint; 8 p:array[0..4] of point; 9 n,f1,f2,h,r,t,k,i:longint; 10 tmp,ans,d,l,l1,l2:double; 11 12 procedure swap(var a,b:point); 13 var c:point; 14 begin 15 c:=a; 16 a:=b; 17 b:=c; 18 end; 19 20 function cmp(a,b:point):boolean; 21 begin 22 if abs(a.y-b.y)j) then 42 begin 43 swap(a[i],a[j]); 44 inc(i); 45 dec(j); 46 end; 47 until i>j; 48 if l 1) and (cross(q[t],q[t-1],i,q[t-1]) k) and (cross(q[t],q[t-1],i,q[t-1]) -eps do k:=k mod t+1; 94 while (mul(q[i+1],q[i],q[r mod t+1],q[i])-mul(q[i+1],q[i],q[r],q[i])>-eps) do r:=r mod t+1; 95 if i=1 then h:=r; 96 while (mul(q[i+1],q[i],q[h mod t+1],q[i])-mul(q[i+1],q[i],q[h],q[i]) tmp then102 begin103 ans:=tmp;104 // writeln(tmp,' ',a[q[i]].x,' ',a[q[i]].y,' ',l2/d);105 p[0].x:=a[q[i]].x+(a[q[i+1]].x-a[q[i]].x)*l2/d;106 p[0].y:=a[q[i]].y+(a[q[i+1]].y-a[q[i]].y)*l2/d;107 // writeln(p[0].x,' ',p[0].y);108 p[1].x:=p[0].x+(a[q[r]].x-p[0].x)*l/dis(p[0],a[q[r]]);109 p[1].y:=p[0].y+(a[q[r]].y-p[0].y)*l/dis(p[0],a[q[r]]);110 p[2].x:=p[1].x-(p[0].x-a[q[i]].x)*(l2-l1)/dis(p[0],a[q[i]]);111 p[2].y:=p[1].y-(p[0].y-a[q[i]].y)*(l2-l1)/dis(p[0],a[q[i]]);112 p[3].x:=p[2].x-(p[1].x-p[0].x);113 p[3].y:=p[2].y-(p[1].y-p[0].y);114 end;115 end;116 writeln(ans:0:5);117 h:=0;118 for i:=1 to 3 do119 if cmp(p[i],p[h]) then h:=i;120 for i:=0 to 3 do121 writeln(p[(h+i) mod 4].x:0:5,' ',p[(h+i) mod 4].y:0:5);122 end.