Codeforces 600D area of Circles ' intersection

Source: Internet
Author: User
Tags define local

Separation, inclusion, want to make three kinds of situations to discuss.

is mainly the accuracy and data range of the problem, the first data with a long double, can be judged by the integer type should not use floating-point type.

The coordinates given in the title, the radius of the integer type, there is a card floating point to judge the situation is relatively small.

At the end of the Triangle area of the time do not use Helen Formula, there are four connected multiply very easy to explode data range loss accuracy, even if 22 times to consider the symbol

(Taking the logarithm is also a good way). (I don't know how the accuracy of sqrt and Cos,sin compare

#include <bits/stdc++.h>using namespaceStd;typedefLong DoubleLd;typedefLong Longll;ld x[2],y[2],r[2];inline ld SQR (ld x) {returnx*x;} inline ll SQRL (ll x) {returnx*x;} Inline LD Fcos (ld A, LD B, ld c) {returnACOSL ((a*a+b*b-c*c)/(2*a*b));} Inline LD cut (LD ang, ld R) {ld S1= ang*r*R; LD S2= Sinl (ANG) *cosl (ANG) *r*R; returnS1-S2;}ConstLD pi = ACOSL (-1);Doublesolve () {if(r[0] > r[1]) {Swap (r[0],r[1]); Swap (x[0],x[1]); Swap (y[0],y[1]); } LL DX= x[0]-x[1], dy = y[0]-y[1]; LL DS= SQRL (dx) +sqrl (DY); if(DS >= SQRL (r[0]+r[1]))return 0; LD D=Sqrtl (DS); if(d+r[0] <= r[1])returnSQR (r[0])*Pi; LD ang[2]; ang[0] = Fcos (d,r[0],r[1]); ang[1] = Fcos (d,r[1],r[0]); /*WA-ld area = ANG[1]*SQR (r[1]) + ANG[0]*SQR (r[0]);    LD s = (d+r[0]+r[1])/2; Area-= Sqrtl (s* (s-d) * (S-r[0]) * (s-r[1]) * *;    O (n^4) Split the sign problem logarithm may be feasible return area; */    returnCut (ang[0],r[0]) + Cut (ang[1],r[1]);}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifCin>>x[0]>>y[0]>>r[0]>>x[1]>>y[1]>>r[1]; printf ("%.10f\n", Solve ()); return 0;}

Codeforces 600D area of Circles ' 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.