Lightoj 1118 incredible molecules Circle area intersection, template

Source: Internet
Author: User
Tags acos sin

See Kuangbin God's version of the son, their own are afraid to put on the ...

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <stack>

using namespace Std;
Const double Pi=acos (-1.0);
const double EPS=1E-10;
Double Add (double a,double b)//floating-point addition with error
{
if (ABS (A + B) < EPS * (ABS (a) + ABS (b))) return 0;
return a + B;
}
struct POINT
{
Double x, y;
Point (double tx = 0,double ty = 0): X (TX), y (ty) {}
Point operator + (point P)
{
Return point (Add (x,p.x), add (Y,P.Y));
}
Point operator-(point P)
{
Return point (Add (x,-p.x), add (Y,-P.Y));
}
Point operator * (double D)
{
return Point (x * d,y * d);
}
Point operator/(double D)
{
Return point (X/D,Y/D);
}
Point Move (double a,double D)//starting from X positive direction, counterclockwise
{
return point (x + d * cos (a), y + d * sin (a));
}
void Read ()
{
scanf ("%lf%lf", &x,&y);
}
};

struct Circle
{
Point O;
Double R;
Circle (Double tx = 0,double Ty = 0,double tr = 0): O (tx,ty), R (TR) {}
void Read ()
{
O.read ();
scanf ("%lf", &r);
}
void Out ()
{
printf ("%.8f%.8f%.8f\n", o.x,o.y,r);
}
Double Area ()
{
return R*R*PI;
}
};
Double X_mult (Point sp, Dot EP, point op)//cross product
{
Return (sp.x-op.x) * (EP.Y-OP.Y)-(SP.Y-OP.Y) * (ep.x-op.x);
}
Double Cross (Point a,point b,point C)//dot Product
{
Return (a.x-c.x) * (b.x-c.x) + (A.Y-C.Y) * (B.Y-C.Y);
}
Double Dist (point A,point B)
{
return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));
}
Double Solve (Circle c1,circle C2)
{
Double D=dist (C1.O,C2.O);
if (c1.r+c2.r<d+eps) return 0;
if (D<fabs (C1.R-C2.R) +eps)
{
Double R=min (C1.R,C2.R);
return pi*r*r;
}
Double x= (D*D+C1.R*C1.R-C2.R*C2.R)/(2*D);
Double T1=acos (X/C1.R);
Double T2=acos ((d-x)/C2.R);
return C1.r*c1.r*t1+c2.r*c2.r*t2-d*c1.r*sin (T1);
}
int main ()
{
int T,ncas=1;
scanf ("%d", &t);
while (t--)
{
Circle c1,c2;
C1. Read ();
C2. Read ();
printf ("Case%d:%.10f\n", Ncas++,solve (C1,C2));
}
return 0;
}

Lightoj 1118 incredible molecules Circle area intersection, template

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.