Bzoj 4445 [SCOI2015] xiao Convex want to run

Source: Internet
Author: User

Main topic: A convex hull, a random point makes it with the first two points of the area than the other two adjacent points small area of the probability

According to the test Instructions column equation, the ratio of the intersection area of N lines to the area of the original convex hull is finally obtained.

1#include <bits/stdc++.h>2 #defineMAXN 1000103 #defineEPS 1e-104 using namespacestd;5 Doubleans,s1,s2;6 structp{7     Doublex, y;8PDoubleA=0,Doubleb=0) {x=a,y=b;}9 };Ten structl{ One P A, b; A     Doubleang; - }; - intSgnDoublex) { the     return(x>eps)-(x<-EPS); - } -Poperator-(P a,p b) { -     returnP (a.x-b.x,a.y-b.y); + } - Double operator*(P a,p b) { +     returna.x*b.y-a.y*b.x; A } at BOOL operator<(L a,l b) { -     if(SGN (a.ang-b.ang)! =0)returna.ang<B.ang; -     return(A.A-B.A) *a.b<0; - } - intN; - P S[MAXN]; in L L[MAXN],Q[MAXN]; P P[MAXN]; - inth,r,tot,cnt; to L get_line (P a,p b,p c,p D) { + l l; -     Doublea=-a.y-d.y+b.y+c.y; the     Doubleb=-b.x-c.x+a.x+d.x; *     Doublec=-a.x*b.y-d.x*c.y+b.x*a.y+c.x*D.y; $L.b=p (b,-a);Panax Notoginseng     if(SGN (a)! =0) L.a=p (-C/A,0); -     ElseL.a=p (0,-c/b); the     returnl; + } A voidGet_line () { the      for(intI=2; i<=n;++i) +L[++cnt]=get_line (s[1],s[2],s[i],s[i+1]); -      for(intI=1; i<=n;++i) { $L[++cnt].a=S[i]; $l[cnt].b=s[i+1]-S[i]; -     } -      for(intI=1; i<=cnt;++i) thel[i].ang=atan2 (l[i].b.y,l[i].b.x); - }Wuyi P Inter (L a,l b) { theP p=b.a-a.a; -     Doublet= (p*b.b)/(a.b*b.b); Wu P ans; -ans.x=a.a.x+a.b.x*T; Aboutans.y=a.a.y+a.b.y*T; $     returnans; - } - BOOLJud (L a,l b,l c) { -P p=Inter (A, b); A     return(P-C.A) *c.b>0; + } the voidGet_point () { -Sort (L +1, l+cnt+1); tot=1; $      for(intI=2; i<=cnt;++i) the         if(SGN (l[i].ang-l[i-1].ang)! =0) thel[++tot]=L[i]; thecnt=tot;tot=0, h=1; theq[++r]=l[1];q[++r]=l[2]; -      for(intI=3; i<=cnt;++i) { in         if(SGN (q[r].b*q[r-1].B) = =0)return; the         if(SGN (q[h].b*q[h+1].B) = =0)return; the          while(H<r&&jud (q[r-1],q[r],l[i]) r--; About          while(H<r&&jud (q[h+1],q[h],l[i]) h++; theq[++r]=L[i]; the     } the      while(H<r&&jud (q[r-1],Q[R],Q[H]) r--; +      while(H<r&&jud (q[h+1],Q[H],Q[R]) h++; -q[r+1]=Q[h]; the      for(inti=h;i<=r;++i)BayiP[++tot]=inter (q[i],q[i+1]); thep[++tot]=p[1]; the } - Doubleget_s (P a[],intCNT) { -     Doubleans=0; the     if(cnt<3)return 0; the      for(intI=1; i<cnt;++i) { theans+=a[i]*a[i+1]; the     } -Ans=fabs (ans/2); the     returnans; the } the voidinit () {94scanf"%d",&n); the      for(intI=1; i<=n;++i) { the         intX,Y;SCANF ("%d%d",&x,&y); thes[i].x=x;s[i].y=y;98     } Abouts[n+1]=s[1]; - }101 voidWork () {102 get_line ();103 get_point ();104s1=get_s (s,n+1); theS2=get_s (p,tot);106ans=s2/S1;107printf"%.4LF", ans);108 }109 intMain () { the init ();111 Work (); the     return 0;113}
View Code

Bzoj 4445 [SCOI2015] xiao Convex want to run

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.