[bzoj4445] [Half plane intersection] small convex want to run __bzoj

Source: Internet
Author: User

4445: [Scoi2015] small convex want to run

Time Limit:2 Sec Memory limit:128 MB
submit:756 solved:280
[Submit] [Status] [Discuss]
Description

Xiao Convex evening like to go to the playground to run, today he finished two laps, he played such a game.
The playground is a convex n-shaped, n vertices are numbered counterclockwise from the 0~n-l. Now the little convex random stands at a place in the playground, marked as
P Point. The P-point and N-vertices are connected to each other to form n triangles. If the P-point, number No. 0, and point 1th form the face of the triangle
The product is the smallest of the n triangles, and the small convex is considered to be a correct stance.
Now little Cam wants to know what the probability is that he will be right at once.
Input

Line 1th contains 1 integer n, which represents the number of vertices and the number of games in the playground.
Next there are n rows, each containing 2 integers xi,yi representing the coordinates of the vertices.
The input guarantees that the points are entered in a counter-clockwise order, all of which are guaranteed to form an n polygon. All points guarantee no three-point collinear.
Output

Output 1 numbers, the correct position of the probability, to retain 4 decimal places.
Sample Input

5

1 8

0 7

0 0

8 0

8 8
Sample Output

0.6316
HINT

3<=n<=10^5,-10^9<=x,y<=10^9

Source Sol:

Notice that a few of the conditions given by the topic are actually several half planes, so just ask for a turn.

#include <cstdio> #include <algorithm> #include <string> #include <cstring> #include <
cstdlib> #include <cmath> #include <iostream> using namespace std;
typedef double S64;
int n,m;
    inline int read () {char C;
    int res,flag=0; while ((C=getchar ()) > ' 9 ' | |
    c< ' 0 ') if (c== '-') flag=1;
    res=c-' 0 ';
    while ((C=getchar ()) >= ' 0 ' &&c<= ' 9 ') res= (res<<3) + (res<<1) +c-' 0 ';
return flag?-res:res;

const int n=200007;
    struct P {s64 x,y;
    Friend inline P operator + (const p &AMP;A,CONST p &b) {return (P) {A.X+B.X,A.Y+B.Y};
    Friend inline P operator-(const p &AMP;A,CONST p &b) {return (P) {A.X-B.X,A.Y-B.Y};
    Friend inline P operator * (const P &AMP;A,S64 b) {return (P) {a.x*b,a.y*b};
    Friend Inline S64 operator * (const p &AMP;A,CONST p &b) {return a.x*b.y-a.y*b.x; Friend inline S64 operator/(const p &AMP;A,CONST p &b) {RetuRN A.x*b.x+a.y*b.y;
}}po[n],p[n];
    struct L {P a,b,v;
    S64 ang; Friend inline bool operator < (const l &AMP;A,CONST l &b) {return A.ang<b.ang| |
    a.ang==b.ang&&a.v* (B.B-A.A) >0;
        Friend Inline P Inter (const L &AMP;A,CONST l &b) {p nw=b.a-a.a;
        S64 tt= (NW*A.V)/(A.V*B.V);
    return B.A+B.V*TT;
    Friend inline bool Jud (const P &a,const L &b) {return b.v* (A-B.A) <0;
}}l[n],q[n];
int Cnt,tot;
S64 Ans,pre;
S64 F[n][3];
    inline void init () {n=read ();
    for (int i=1;i<=n;++i) scanf ("%lf%lf", &po[i].x,&po[i].y);
    PO[N+1]=PO[1];
        for (int i=1;i<=n;++i) {l[++cnt]= (l) {po[i],po[i+1],po[i+1]-po[i]};
        L[cnt].ang=atan2 (l[cnt].v.y,l[cnt].v.x);
        PRE+=PO[I]*PO[I+1];
        F[I][0]=PO[I].Y-PO[I+1].Y-F[1][0];
        F[I][1]=PO[I+1].X-PO[I].X-F[1][1];
        F[I][2]=PO[I]*PO[I+1]-F[1][2];
 if (i!=1) {P x,y,v;           x.x=x.y=0;
            if (!f[i][1]) x.x=-f[i][2]/f[i][0];
            else x.y=-f[i][2]/f[i][1];
            V.X=F[I][1];
            V.Y=-F[I][0];
            Y=x+v;
            L[++cnt]= (L) {x,y,v};
        L[cnt].ang=atan2 (v.y,v.x);
}//L[++cnt]= (L) {po[1],po[2],po[2]-po[1]};
L[cnt].ang=atan2 (l[cnt].v.y,l[cnt].v.x);
        /* for (int i=1;i<=cnt;++i) {printf ("%.4lf%.4lf", L[I].A.X,L[I].A.Y);
    printf ("%.4lf%.4lf\n", l[i].v.x,l[i].v.y);
    }*/} inline void Solve () {sort (l+1,l+1+cnt);
        for (int i=1;i<=cnt;++i) {if (L[i].ang!=l[i-1].ang) ++tot;
    L[tot]=l[i];
    } Cnt=tot;
    tot=0;
    int l=1,r=2;
    Q[1]=L[1];Q[2]=L[2];
        for (int i=3;i<=cnt;++i) {while (L<r&&jud (Inter (Q[R-1],Q[R)), l[i]) r--;
        while (L<r&&jud (Inter (Q[L+1],Q[L), l[i]) ++l;
    Q[++r]=l[i];
    while (L<r&&jud (Inter (Q[R-1],Q[R)), q[l]) r--; while (L<r&&juD (Inter (Q[l+1],q[l]), q[l]) ++l;
    Q[R+1]=Q[L]; 
for (int i=1;i<=r;++i) P[++tot]=inter (q[i],q[i+1]);
    } inline void Calc () {for (int i=1;i<tot;++i) ans+=p[i]*p[i+1];
    ANS+=P[TOT]*P[1];
    if (tot<3) ans=0;
printf ("%.4lf", Ans/pre);
    int main () {//Freopen ("Convex.in", "R", stdin);//Freopen ("Convex.out", "w", stdout);
    Init ();
    Solve ();
Calc (); }

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.