Topic Links:
Intersection
Time limit:4000/4000 MS (java/others)
Memory limit:512000/512000 K (java/others)
problem DescriptionMatt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures is some famous examples.
A ring is a 2-d figure bounded by the circles sharing the common center. The radius for these circles is denoted by R and R (R < R). For more details, refer to the gray part in the illustration below.
Matt just designed a new logo consisting of the rings with the same size in the 2-d plane. For he interests, Matt would like to know the area of the intersection of these.
InputThe first line contains only one integer T (t≤105), which indicates the number of test cases. For each test case, the first line contains the integers R, R (0≤r < r≤10).
Each of the following, lines contains, integers xi, yi (0≤xi, yi≤20) indicating the coordinates of the center of Each ring.
OutputFor each test case, output a single line ' case #x: Y ', where x is the case number (starting from 1) and Y are the area of I Ntersection rounded to 6 decimal places.
Sample Input 22 30 00 02 30 05 0
Sample Output case #1:15.707963Case #2:2.250778
Test Instructions: Find the area where two rings intersect;
Ideas: ans= two large circle area intersection + two small round area intersection -2* Big circle with small round area intersection;
AC Code:
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intn=1e5+6;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);DoubleFunDoubleXDoubleYDoubleFxDoubleFyDoubleRDoubleR) {DoubleDis=sqrt ((X-FX) * (X-FX) + (y-fy) * (yfy)); //cout<<dis<<endl; if(DIS>=R+R)return 0; Else if(dis<=r-r) {returnpi*r*R; } Else { Doubleangle1,angle2,s1,s2,s3,s; Angle1=acos ((r*r+dis*dis-r*r)/(2*r*dis)); Angle2=acos ((r*r+dis*dis-r*r)/(2*r*dis)); S1=angle1*r*r;s2=angle2*r*s; S3=r*dis*sin (angle1); S=s1+s2-S3; returns; }}intMain () {intT; scanf ("%d",&t); DoubleR,r,x,y,fx,fy; intCnt=1; while(t--) {scanf ("%LF%LF",&r,&R); scanf ("%LF%LF%LF%LF",&x,&y,&fx,&y); Doubleans1,ans2,ans3,ans4; Ans1=Fun (x,y,fx,fy,r,r); Ans2=Fun (x,y,fx,fy,r,r); ANS3=Fun (x,y,fx,fy,r,r); ANS4=Fun (fx,fy,x,y,r,r); printf ("Case #%d:", cnt++); printf ("%.6lf\n", ans1+ans2-ans3-ans4); }}
hdu-5120 intersection (computational geometry)