HDU 5120 Intersection

Source: Internet
Author: User
Tags acos

IntersectionTime limit:4000/4000 MS (java/others) Memory limit:512000/512000 K (java/others)
Total submission (s): 967 Accepted Submission (s): 371


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 was the case number (starting from 1) and Y-is the being A of intersection rounded to 6 decimal places.

Sample Input
22 30 00 02 30 05 0

Sample Output
Case #1:15.707963Case #2:2.250778

Source

2014ACM/ICPC Asia Beijing Station-Replay (thanks to the North Division and handing in)

Geometric calculations,,, a little trouble

 #include <cstdio> #include <cmath> #include <algorithm>using namespace Std;int a1,a2,b1,b2;double d,p;double area;double fun (int a,int b) {double sa,sb;d=sqrt ((A1-A2) * (A1-A2) + (b1-b       2) * (B1-B2));//center distance double Rr=min (A, B), if (D<=abs (a))//internal or inner-cut Area=acos ( -1.0) *rr*rr;else if (d>=a+b)//tangent or disjoint    area=0.0;else{//Intersection for Area p= (a+b+d)/2.0;//Helen formula inside the P-sa=acos ((a*a+d*d-b*b)/(2.0*a*d));//c^2=a^2+b^2-2*a*b*cos; Find Central angle Sb=acos ((b*b+d*d-a*a)/(2.0*b*d)); Ibid. area=sa*a*a+sb*b*b-2*sqrt (p* (p-a) * (p-b) * (p-d)),//two sector area and the area of the triangle minus the surface, the area of the intersection} return areas;} int main () {int t,k=0;int r,r;double s1,s2,s3,sum;while (scanf ("%d", &t)!=eof) {while (t--) {k++; scanf ("%d%d%d%d%d%d ", &R,&R,&A1,&B1,&A2,&B2); S1=fun (R,R); S2=fun (R,R); S3=fun (r,r);//The ring can be seen as two circles, you can see the law, the area of two rings is equal to//two large circle intersection area minus two times the large circle and the small Circle intersection area, plus two small circle intersection area if (r>r) sum=s1-2*s3+s2; else sum=s2-2*s3+s1; printf ("Case #%d:%.6lf\n", k,sum);}} return 0;} 


HDU 5120 Intersection

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.