POJ 3675 Telescope

Source: Internet
Author: User
Tags acos

Test instructions: Given a polygon that is not self-intersection, the area of the circle at the origin is required and the center of the circle is intersection.

Ideas: With POJ2986, is the enhanced version

Code:

1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 structpoint{7     Doublex, y;8 Point () {}9Point (DoubleX0,Doubley0): X (x0), Y (y0) {}Ten}p[200005],a[5],o; One structline{ A Point s,e; - Line () {} - Line (Point S0,point E0): S (s0), E (E0) {} the }; - intN; - DoubleR; - Const Doubleeps=1e-8; + Const DoublePi=acos (-1); - DoubleSgnDoublex) { +     if(x>eps)return 1.0; A     if(x<-eps)return-1.0; at     return 0; - } -Pointoperator* (Point P1,Doublex) { -     returnPoint (p1.x*x,p1.y*x); - } -Pointoperator/(Point P1,Doublex) { in     returnPoint (p1.x/x,p1.y/x); - } to Double operator/(Point p1,point p2) { +     returnp1.x*p2.x+p1.y*p2.y; - } the Double operator*(Point p1,point p2) { *     returnp1.x*p2.y-p1.y*p2.x; $ }Panax NotoginsengPointoperator+(Point p1,point p2) { -     returnPoint (p1.x+p2.x,p1.y+p2.y); the } +Pointoperator-(Point p1,point p2) { A     returnPoint (p1.x-p2.x,p1.y-p2.y); the } + Doubledis (point p1) { -     returnsqrt (p1.x*p1.x+p1.y*p1.y); $ } $ Doubledis (point p1,point p2) { -     returnDis (Point (p1.x-p2.x,p1.y-p2.y)); - } the DoubleSqrDoublex) { -     returnx*x;Wuyi } the DoubleDist_line (line p) { -     Doublea,b,c,dist; Wua=p.s.y-p.e.y; -b=p.s.x-p.e.x; Aboutc=p.s.x*p.e.y-p.s.y*p.e.x; $Dist=fabs (C)/sqrt (SQR (A) +Sqr (B)); -     returnDist; - } - DoubleGet_cos (DoubleADoubleBDoublec) { A     return(b*b+c*c-a*a)/(2*b*c); + } the DoubleGet_angle (Point p1,point p2) { -     if(!SGN (Dis (p1)) | |! SGN (Dis (p2)))return 0.0; $     Doublea,b,c; theA=dis (p1); theb=dis (p2); theC=dis (P1,P2); the     if(c<=eps)return 0.0; -     returnACOs (Get_cos (c,a,b)); in } the Point Get_point (point p) { the     DoubleT=SQR (p.x) +Sqr (P.Y); About     returnPoint (SGN (p.x) *sqrt (SQR (p.x)/T), SGN (P.Y) *sqrt (SQR (P.Y)/T)); the } the DoubleS (Point p1,point p2,point p3) { the     returnFabs ((P2-P1) * (P3-P1))/2; + } - DoubleWork (Point p1,point p2) { the     DoubleF=SGN (P1*P2), res=0;Bayi     if(!SGN (f) | |! SGN (Dis (p1)) | |! SGN (Dis (p2)))return 0.0; the     DoubleL=Dist_line (Line (P1,P2)); the     DoubleA=dis (p1); -     Doubleb=dis (p2); -     DoubleC=dis (P1,P2); the     if(a<=r&&b<=R) { the         returnFabs (P1*P2)/2.0*F; the     } the     if(a>=r&&b>=r&&l>=R) { -         Doubleang=Get_angle (P1,P2); the         returnFabs ((ang/(2.0)) * (R*R)) *F; the     } the     if(a>=r&&b>=r&&l<=r&& (Get_cos (a,b,c) <=0|| Get_cos (b,a,c) <=0)){94         Doubleang=Get_angle (P1,P2); the         returnFabs ((ang/(2.0)) * (R*R)) *F; the     } the     if(a>=r&&b>=r&&l<=r&& (Get_cos (a,b,c) >0&&get_cos (B,A,C) >0)){98         Doubledist=Dist_line (Line (P1,P2)); About         DoubleLen=sqrt (Sqr (R)-SQR (dist)) *2.0; -         Doubleang1=Get_angle (P1,P2);101         DoubleCos2=Get_cos (len,r,r);102Res+=fabs (len*dist/2.0);103         DoubleAng2=ang1-ACOs (COS2);104Res+=fabs ((ang2/(2)) * (r*R)); the         returnRes*F;106     }107     if((a>=r&&b<r) | | (a<r&&b>=s)) {108         if(b>a) Std::swap (A, B), Std::swap (P1,P2);109         DoubleT=SQR (p1.x-p2.x) +SQR (p1.y-p2.y); thePoint U=point (SGN (p1.x-p2.x) *sqrt (SQR (p1.x-p2.x)/T), SGN (P1.Y-P2.Y) *sqrt (SQR (P1.Y-P2.Y)/T));111         Doubledist=Dist_line (Line (P1,P2)); the         DoubleLEN=SQRT (r*r-dist*Dist);113         DoubleLen2=sqrt (Sqr (Dis (p2))-Sqr (Dist)); the         if(Fabs (DIS (p2+u*len2)-dist) <=eps) len+=Len2; the         Elselen-=Len2; thePoint p=p2+u*Len;117res+=S (o,p2,p);118         Doubleang=Get_angle (p1,p);119Res+=fabs ((ang/2.0) *r*R); -         returnRes*F;121     }122     return 0;123 }124 intMain () { theO=point (0,0);126      while(SCANF ("%LF", &r)! =EOF) {127scanf"%d",&n); -          for(intI=1; i<=n;i++)129scanf"%LF%LF",&p[i].x,&p[i].y); thep[n+1]=p[1];131         Doubleans=0; the          for(intI=1; i<=n;i++)133Ans+=work (p[i],p[i+1]);134ans=fabs (ans); 135printf"%.2f\n", ans); 136     }137}

POJ 3675 Telescope

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.