Intersection (HDU5120 + round-cross area)

Source: Internet
Author: User
Tags acos

Topic Links:

  http://acm.hdu.edu.cn/showproblem.php?pid=5120

Topic:

Test instructions

  Find the area where two rings intersect.

Ideas:

Two large circle area cross -2x large circle with small round area intersection + two small round area sex.

The code is implemented as follows:

1#include <Set>2#include <map>3#include <deque>4#include <ctime>5#include <stack>6#include <cmath>7#include <queue>8#include <string>9#include <cstdio>Ten#include <vector> One#include <iomanip> A#include <cstring> -#include <iostream> -#include <algorithm> the using namespacestd; -  -typedefLong LongLL; -typedef PAIR&LT;LL, Ll>PLL; +typedef PAIR&LT;LL,int>Pli; -typedef pair<int,int>PII; +typedef unsignedLong LongULL; A  at #defineLson rt<<1 - #defineRson rt<<1|1 - #defineNAME2STR (name) (#name) - #defineBug printf ("**********\n"); - #defineIO Ios::sync_with_stdio (FALSE); - #defineDebug (x) cout<< #x << "=[" <<x<< "]" <<endl; in #defineFIN freopen ("/home/dillonh/clionprojects/in.txt", "R", stdin); -  to Const DoubleEPS = 1e-8; + Const intMAXN = 1e5 +7; - Const intINF =0x3f3f3f3f; the Const DoublePI = ACOs (-1.0); * ConstLL INF =0x3f3f3f3f3f3f3f3fll; $ Panax Notoginseng intT, R, R; - intx1, x2, yy, y2; the  + DoubleCirinter (intX1,intY1,intR1,intX2,intY2,intR2)//formula of round intersection area A { the     DoubleD,s,t,a1,a2,s1,s2,s3; +     if(r1<r2) Swap (r1, r2); -D=sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));//Two center distance $     if(D&GT;=R1+R2)return 0;//two Yuan $     Else if(d<= (R1-R2))//Two circle included -s=pi*r2*R2; -     Else{//Two circle intersection theA1=acos ((R1*R1+D*D-R2*R2)/(2*R1*D));//half of the circle's Center angle -A2=acos ((R2*R2+D*D-R1*R1)/(2*R2*D));//half of the circle's Center angleWuyiS1=A1*R1*R1;//The fan area in the big circle theS2=A2*R2*R2;//The fan area in the small circle -S3=r1*sin (A1) *d;//two quadrilateral area of the center and two intersections WuS=S1+S2-S3;//area of round cross -     } About     returns; $ } -  - intMain () { - #ifndef Online_judge A FIN; + #endif thescanf"%d", &t); -     intIcase =0; $      while(t--) { thescanf"%d%d", &r, &R); thescanf"%d%d%d%d", &x1, &yy, &AMP;X2, &y2); the         DoubleAns = cirinter (x1, yy, R, x2, Y2, R)-2* Cirinter (x1, yy, R, x2, Y2, R) +cirinter (x1, yy, R, x2, Y2, R); theprintf"Case #%d:%.6f\n", ++icase, ans); -     } in     return 0; the}

Intersection (HDU5120 + round-cross area)

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.