POJ 3384 half-plane cross

Source: Internet
Author: User

Feng Shui
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 5183 Accepted: 1548 Special Judge

Description

Feng Shui is the ancient Chinese practice of placement and arrangement of space to achieve harmony with the environment. George had recently got interested in it, and now wants to apply it to the his home and bring harmony to it.

There is a practice which says this bare floor was bad for living area since spiritual energy drains through it, so George Purchased-similar round-shaped carpets (Feng Shui says that straight lines and sharp corners must is avoided). Unfortunately, he is unable to cover the floor entirely since the the hostel has shape of a convex polygon. But he still wants to minimize the uncovered area by selecting the best placing for his carpets, and asks your to help.

You need-to-place-carpets in the the-the-so-the-the-covered by both-carpets is maximal possible. The carpets may overlap, but they is not being cut or folded (including cutting or folding along the floor border)-feng sh UI tells to avoid straight lines.

Input

The first line of the input file contains, numbers n and R -the number of corners in George ' S (3≤ n ≤100) and the radius of the carpets (1≤ R ≤1000, both carpets have the same radius). The following n lines contain II integers XI and Yi each-coordinates of the I-th Co Rner (−1000≤ Xi, Yi ≤1000). Coordinates of all corners is different, and adjacent walls of the "the" is not collinear. The corners is listed in clockwise order.

Output

Write four numbers x1, y1, x2, y2 to the output file, where (x1, y1) and (x2, y2) denote the spots where carpet centers should be placed. Coordinates must is precise up to 4 digits after the decimal point.

If there is multiple optimal placements available, return any of them. The input data guarantees is at least one solution exists.

Sample Input

#1 5 2
-2 0
-5 3
0 8
3 ·
5 0
#2 4 3
0 0
0 8
10 8
10 0

Sample Output

#1 -2 3 3 2.5
#2 3 5 7 3

 

/*poj 3384 give you a polygon, and then put two circles inside, The maximum area that can be accounted for. This is equivalent to making the circle as far away as possible if you can put down two circles. If you translate each edge of the polygon to the inside, the length of the radius R. Then the rest of the polygon is the center of the pick-up range and then on this basis to enumerate the points. , and then enumerate its vertices. However, the length of the side of the translated polygon does not change, so it can be seen as a polygon with multiple lines. Then it becomes the half-plane intersection problem (that is, give you straight lines and graphs on which side of the line, and then the polygon) hhh-2016-05-17 19:55:56*/#include <iostream> #include <vector># Include <cstring> #include <string> #include <cstdio> #include <queue> #include <cmath># Include <algorithm> #include <functional> #include <map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef LONG LONG ll;using namespace Std;const int maxn = 300;const double PI = 3.1415926;c    Onst double eps = 1e-10;int sgn (double x) {if (Fabs (x) < EPS) return 0;    if (x < 0) return-1; else return 1;}    struct point{double x, y;    Point () {}, point (double _x,double _y) {x = _x,y = _y;    } Point operator-(const point &b) const {return point (X-B.X,Y-B.Y); } Double Operator ^ (const point &b) const {return x*b.y-y*b.x;    } Double operator * (const point &b) Const {return x*b.x + y*b.y;    }};struct line{Point s,t;    Double k;        Line () {} line (point _s,point _t) {s = _s;        t = _t;    K = atan2 (t.y-s.y,t.x-s.x);        } Point operator & (const line &b) Const {Point res = s;        Double Ta = ((S-B.S) ^ (b.s-b.t))/((s-t) ^ (b.s-b.t));        Res.x + = (t.x-s.x) *ta;        Res.y + = (t.y-s.y) *ta;    return res;    }};bool hpicmp (line A,line b) {if (Fabs (A.K-B.K) > EPS) return a.k<b.k; Return ((A.S-B.S) ^ (B.T-B.S) < 0;}    Line LI[MAXN];d ouble calarea (point p[],int N) {double ans = 0;    for (int i = 0; i < n; i++) {ans + = (p[i]^p[(i+1)%n])/2; } return ans; Double Dist (point A,point b) {return sqrt ((a) * (a));}    void HPI (line line[],int n,point res[],int &resn) {int tot =n;    Sort (line,line+n,hpicmp);    tot = 1; for (int i = 1; i < n; i++) {if (Fabs (LINE[I].K-LINE[I-1].K) > EPS) line[tot++] = Line[i];    } int head = 0,tail = 1;    Li[0] = line[0];    LI[1] = line[1];    RESN = 0;                for (int i = 2; i < tot; i++) {if (Fabs ((LI[TAIL].T-LI[TAIL].S) ^ (LI[TAIL-1].T-LI[TAIL-1].S)) < eps| |        Fabs ((LI[HEAD].T-LI[HEAD].S) ^ (LI[HEAD+1].T-LI[HEAD+1].S) < EPS) return; while (Head < tail && (((Li[tail] & Li[tail-1])-LINE[I].S) ^ (LINE[I].T-LINE[I].S)) > EPS) t        ail--; while (Head < tail && (((Li[head] & li[head+1])-LINE[I].S) ^ (LINE[I].T-LINE[I].S)) > EPS) H        ead++;    Li[++tail] = Line[i];        } while (Head < tail && (((Li[tail] & Li[tail-1])-LI[HEAD].S) ^ (LI[HEAD].T-LI[HEAD].S)) > EPS)    tail--; while (Head < tail && (((Li[head] & li[head-1)-Li[tail].s) ^ (li[tail].t-li[tail].t)) > EPS) he    ad++;        if (tail <= head+1)Return    for (int i = head; i < tail; i++) res[resn++] = li[i]&li[i+1];    if (Head < TAIL-1) res[resn++] = li[head]&li[tail];    Double Mans =-1;    int ANSI,ANSJ;  for (int i = 0, i < RESN; i++) {for (int j = 0; J < Resn; J + +) if (SGN (Dist (res[i],res[j))-mans)                >= 0) {Mans = dist (res[i],res[j]);            ANSI = I,ANSJ = j; }} printf ("%.4f%.4f%.4f%.4f\n", res[ansi].x,res[ansi].y,res[ansj].x,res[ansj].y);} Point P0; Point LIS[MAXN];    Line Line[maxn];bool CMP (point A,point b) {Double t = (a-p0) ^ (B-P0);    if (SGN (t) > 0) return true;    else if (SGN (t) = = 0 && sgn (Dist (a,lis[0])-dist (B,lis[0])) <= 0) return true; else return false;} Point TA,TB;    Point tans[maxn];void fin (Point a,point b,double mid) {Double len = dist (A, b);    Double dx = (A.Y-B.Y) *mid/len;    Double dy = (b.x-a.x) *mid/len;    ta.x = A.X+DX,TA.Y = A.y+dy; tb.x = B.X+DX,TB.Y = B.y+dy;}    int main () {//freopen ("In.txt", "R", stdin);    int n;    Double R; while (scanf ("%d%lf", &n,&r)! = EOF) {for (int i = 0; i < n; i++) {scanf ("%lf%lf", &am        P;LIS[I].X,&AMP;LIS[I].Y);        } reverse (Lis,lis+n);            for (int i = 0; i < n; i++) {Fin (lis[i],lis[(i+1)%n],r);        Line[i] = line (TA,TB);        } int resn;    HPI (LINE,N,TANS,RESN); } return 0;}

  

POJ 3384 half-plane cross

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.