1825. Ifrit Bomber 2Time limit:0.5 Second
Memory limit:64 MB
The very first use of ifrit bottles caused mass protests from the world community. The UNESCO declared that Ifrit bombardments were destroying the historical centers of large cities, which had a tremendous Cultural importance. Pitirim Schwartz corrected the behavior of Ifrits so, the centers of the cities remained untouched. The destruction zone now is a ring instead of a disk:ifrits destroyed everything that is no closer than
RAnd no farther than
RFrom the impact point of the bottle. To estimate the efficiency of carpet ifrit bombardments, Pitirim needs to being able to calculate the total area of the DESTR Uction zone in the case of dropping-ifrit bottles. Inputthe only input line contains integers
D,
R1,
R1,
R2, and
R2, which is the distance between the impact points of the bottles, the inner and outer radii of destruction of the first B Ottle, and the inner and outer radii of destruction of the second bottle, respectively (0≤
D≤15000; 1≤
rI <
Ri ≤15000). Outputoutput the total destruction area with an absolute or relative error of in most 10? 6. Sample
input |
Output |
200 100 300) 200 300 |
353992.933435
|
Test instructions: Give two rings to find the total area covered by these two rings.
The data given is that the two rings distance d, the inner circle radius of the first ring R1, the outer circle radius R1, and the R2,R2.
Practice: First of the two rings of their respective area, to calculate the total coverage area, then the next only to calculate the intersection of the two areas can be.
The area in which the two intersect is =R1UR2-R1UR2-R1UR2+R1UR2.
One of the R1UR2 is the area of two large circle and.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include < Iostream> #include <algorithm>using namespace std; #include <vector> const Double EPS = 1e-8;const double PI = ACOs ( -1.0); int sgn (double x) {if (Fabs (x) < EPS) return 0;if (x < 0) return-1;else return 1;} struct point{double x, y; Point () {}point (double _x,double _y) {x = _x;y = _y;} Point operator-(const point &b) Const{return Point (X-B.X,Y-B.Y); Cross product double operator ^ (const point &b) Const{return x*b.y-y*b.x;} Dot Product double operator * (const point &b) Const{return x*b.x + y*b.y;} Rotation angle around the origin B (radian value), after the change of x, y, void Transxy (double b) {Double tx = X,ty = Y;x = Tx*cos (b)-Ty*sin (b); y = Tx*sin (b) + ty*cos (b);}} ;d ouble Dist (point A,point b) {return sqrt ((a) * (-a));} Double area (Point c1,double r1,point c2,double R2) {Double d = dist (C1,C2); if (r1 + R2 < D + EPS) return 0;if (D < fabs ( R1-R2) + EPS) {Double r = min (R1,R2); return pi*r*r;} Double x = (d*d + r1*r1-r2*r2)/(2*d);d ouble t1 = ACOs (x/r1);d ouble t2 = ACOs ((d-x)/r2); return r1*r1*t1 + r2*r2*t2-d*r1*sin (t1);} int main () {point cir1,cir2;cir1.y=cir2.y=0;double D; double R1,r1,r2,r2;while (cin>>d>>r1>>r1> >R2>>R2) {cir1.x=0;cir2.x=d; printf ("%lf\n", pi*r1*r1-pi*r1*r1+pi*r2*r2-pi*r2*r2-(Area (CIR1,R1,CIR2,R2)- Area (CIR1,R1,CIR2,R2)-area (CIR1,R1,CIR2,R2) +area (CIR1,R1,CIR2,R2)));} return 0;}
URAL 1825. Ifrit Bomber 22 The area of the circle and