Test instructions: The room is a convex polygon, to lay in the inside two radius r of the round carpet, can overlap, now requires the laying of where, so that the carpet occupies the largest floor area.
Solution: To make the circular carpet occupies the largest area, the round carpet must be tangent to the edge, so as to make as far as possible do not overlap. So we push all the edges inward R, so the polygon is formed, we know that the center of the two round carpet must be on this polygon boundary, the best case is the furthest point of this new convex hull.
The initial polygon is ( -1000,-1000) to (1000,1000) the rectangle, then we can simulate each side of the forward, each cut out a new convex polygon, then the final convex polygon, and then n^2 enumeration to find the furthest point. Here, we use a straight line to cut a convex polygon algorithm.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#defineMod 1000000007#definePi ACOs (-1.0)#defineEPS 1e-8using namespacestd;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {}voidInput () {scanf ("%LF%LF",&x,&y); }};typedef point Vector;structline{point P; Vector v; Doubleang; Line () {} line (point P, Vector v):p (P), V (v) {ang=atan2 (v.y,v.x);} Point Point (DoubleT) {returnPoint (p.x + t*v.x, p.y + t*v.y); } BOOL operator< (ConstLine &l)Const{returnAng <L.ang;}};intDCMP (Doublex) {if(x <-eps)return-1; if(X > EPS)return 1; return 0;} Template<classT> T Sqr (t x) {returnX *x;} Vectoroperator+ (vector A, vector B) {returnVector (a.x + b.x, A.Y +b.y); }vectoroperator-(vector A, vector B) {returnVector (a.x-b.x, A.Y-b.y); }vectoroperator* (Vector A,DoubleP) {returnVector (A.x*p, a.y*p); }vectoroperator/(Vector A,DoubleP) {returnVector (a.x/p, a.y/p); }BOOL operator< (Constpoint& A,Constpoint& b) {returna.x < b.x | | (a.x = = b.x && A.y <b.y); }BOOL operator>= (Constpoint& A,Constpoint& b) {returna.x >= b.x && a.y >=b.y;}BOOL operator<= (Constpoint& A,Constpoint& b) {returna.x <= b.x && a.y <=b.y;}BOOL operator== (Constpoint& A,Constpoint& b) {returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; }DoubleDot (vector A, vector B) {returna.x*b.x + a.y*b.y;}DoubleLength (Vector A) {returnsqrt (Dot (A, a));}DoubleAngle (vector A, vector B) {returnACOs (Dot (A, B)/Length (a)/Length (B)); }DoubleCross (vector A, vector B) {returna.x*b.y-a.y*b.x;} Vector vectorunit (vector x) {returnX/Length (x);} Vector Normal (vector x) {returnPoint (-X.Y, x.x)/Length (x);}DoubleAngle (Vector v) {returnatan2 (V.Y, v.x);} Point Getlineintersection (line A, line B) {Vector u= A.P-B.P; Doublet = Cross (B.V, u)/Cross (A.V, B.V); returnA.P + a.v*t;}DoubleDisP (Point a,point B) {returnLength (b-A);}intLinecrosspolygon (point& l1,point& l2,point* p,intn,point*Poly) { intm =0; for(intI=0, j;i<n;i++) { if(DCMP (l1-p[i],l2-p[i)) >=0) {poly[m++] = P[i];Continue; } J= (I-1+n)%N; if(DCMP (l1-p[j],l2-p[j)) >0) poly[m++] = Getlineintersection (line (L1,L2-L1), line (p[j],p[i]-p[j])); J= (i+1+n)%N; if(DCMP (l1-p[j],l2-p[j)) >0) poly[m++] = Getlineintersection (line (L1,L2-L1), line (p[j],p[i]-p[j])); } returnm;} Line l[122]; Point poly[3][124],p[ $],q1,q2;intlen[3];intMain () {intI,j,pre,now,n; DoubleR; while(SCANF ("%D%LF", &n,&r)! =EOF) {poly[0][0] = Point (- +,- +); poly[0][1] = Point ( +,- +); poly[0][2] = Point ( +, +); poly[0][3] = Point (- +, +); Len[pre=0] =4; for(i=0; i<n;i++) P[i].input (); for(i=0; i<n;i++) { now= pre^1; Vector NV= Normal (p[i]-p[(i+1)%n]); Q1= P[i] + nv*r; Q2 = q1+p[(i+1)%n]-P[i]; Len[now]=Linecrosspolygon (Q2,q1,poly[pre],len[pre],poly[now]); Pre=Now ; } DoubleMaxi =-Mod; for(i=0; i<len[now];i++) for(j=i;j<len[now];j++) { if(DCMP (DisP (poly[now][i],poly[now][j))-maxi) >0) {Maxi=DisP (Poly[now][i],poly[now][j]); Q1= Poly[now][i], q2 =Poly[now][j]; }} printf ("%.6f%.6f%.6f%.6f\n", Q1.X,Q1.Y,Q2.X,Q2.Y); } return 0;}View Code
POJ 3384 Feng Shui--line tangent plane