HDU --- (tell me the Area) (geometric/triangular area and circular area knowledge)

Source: Internet
Author: User
Tags acos
Tell me the area

Time Limit: 3000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1876 accepted submission (s): 567


Problem description There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.
 

 

Inputthere are invalid cases. in each case, there are two lines. each line has three numbers: the coordinates (x and y) of the center of a circle, and the radius of the circle.

 

Outputfor each case, You just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.

 

Sample input0 0 22 2 1

 

Sample output0.108

 

Authorwangye

 

Source 2008 "insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4) for any two circles in the plane, these relations exist: inner and inner tangent, and intersection, exclusive and exclusive. (1) For inner cutting, we only need to find the area of the smallest circle of the area. (2) for outer cutting and outer separation, the area obtained must be 0.0 square meters. (3) for intersection, then we need to find these: know the coordinates of the two points: Find the distance between the two points of DIST; know the three sides, you can find the corresponding angle of the three sides: A ^ 2 + B ^ 2-2 * a * B * Cos (G) = DIST ^ 2; Area of the Quadrilateral: Sm = S3 (area of the triangle) * 2; s3 = SQRT (p * (p-r1) * (p-r2) * (p-D); then find the area corresponding to the two slices: S1, S2 based on: S = 1/2 * g * r; finally: S = S1 + s2-sm; Code:
1 # include <cstdio> 2 # include <cmath> 3 # include <algorithm> 4 # include <iostream> 5 using namespace STD; 6 7 struct circle 8 {9 Double X, y, R; 10}; 11 double dist (Circle A, circle B) 12 {13 return SQRT (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y); 14} 15 int main () 16 {17 circle a, B; 18 double D, P, area, Sb, SA; 19 while (scanf ("% lf", &. x, &. y, &. r, & B. x, & B. y, & B. r )! = EOF) 20 {21 d = dist (a, B); 22 double RR = min (. r, B. r); 23 if (d <= ABS (. r-b.r) // contains or inner cut 24 area = ACOs (-1.0) * RR; 25 else26 if (D> =. R + B. r) 27 Area = 0.0; 28 else {29 p = (. R + B. R + D)/2.0; 30 SA = ACOs (. R *. R + D * d-b.r * B. r)/(2.0 *. R * D); 31 sb = ACOs (B. R * B. R + D * d-a.r *. r)/(2.0 * B. R * D); 32 area = sa *. R *. R + Sb * B. R * B. r-2 * SQRT (p * (p-a.r) * (p-b.r) * (p-D); 33} 34 printf ("%. 3lf \ n ", area); 35} 36 return 0; 37}
View code

 

HDU --- (tell me the Area) (geometric/triangular area and circular area knowledge)

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.