UVa 10969 (cover problem between circle and round) Sweet Dream

Source: Internet
Author: User
Tags acos

Test instructions

There are n a circle of different sizes placed in a sequential order, and the length of all visible arcs is calculated.

Analysis:

This question should be an example of the Great White Book LA 2572 (the number of visible discs) Kanazawa, the overall framework is similar.

For each circle, the amplitude angle corresponding to the intersection of the other circles (converted to [0, 2π]) is ordered, and the end point of each arc is enumerated, and is visible if it is not covered by the circle that is placed behind it.

Attention:

Originally thought WA is the precision problem, later in the major small has been WA, here Precision EPS from 1e-11 to 1e-13 is no problem.

But an equal sign is added when judging whether the end of the arc is covered by a circle. That is, the 64th line of code is <= rather than <

The UVA data is really strong, Orz.

1#include <cstdio>2#include <cmath>3#include <vector>4#include <algorithm>5 using namespacestd;6 7 Const intMAXN = -+Ten;8 Const DoubleEPS = 1e- One;9 Const DoublePI = ACOs (-1.0);Ten Const DoubleTWO_PI =2.0*PI; One DoubleRADIUS[MAXN]; A  - DoubleNormalizeangle (Doubleang) -{returnAng-two_pi*floor (ang/two_pi); } the  - intDCMP (Doublex) - { -     if(Fabs (x) < EPS)return 0; +     returnX <0? -1:1; - } +  A struct Point at { -     Doublex, y; -Point (Doublex=0,Doubley=0): X (x), Y (y) {} - }P[MAXN]; - typedef point Vector; -  in BOOL operator== (Constpoint& A,Constpoint&B) -{returnDCMP (a.x-b.x) = =0&& dcmp (a.y-b.y) = =0; } to  +Pointoperator- (Constpoint& A,Constpoint&B) -{returnPoint (a.x-b.x, A.Y-b.y); } the  * DoubleDot (Constpoint& A,Constpoint&B) ${returna.x*b.x + a.y*b.y;}Panax Notoginseng  - DoubleLength (Constvector&A) the{returnsqrt (Dot (A, a));} +  A DoubleAngle (Constvector&A) the{returnatan2 (A.Y, a.x);} +  - voidGetccintersection (Constpoint& C1,DoubleR1,Constpoint& C2,DoubleR2, vector<Double>&rad) $ { $     DoubleD = Length (C1-C2); -     if(DCMP (d) = =0)return; -     if(DCMP (D-R1-R2) >0)return; the     if(DCMP (D-fabs (R1-R2)) <0)return; - Wuyi     Double Base= Angle (C2-C1); the     DoubleAng = ACOs ((r1*r1 + d*d-r2*r2)/(2.0*r1*d)); -Rad.push_back (Normalizeangle (Base+ang)); WuRad.push_back (Normalizeangle (Base-ang)); - } About  $ intN; -  - BOOLIsVisible (Constpoint& C,intID) - { A      for(inti = ID +1; I < n; ++i) +     { the         DoubleD = Length (C-p[i]); -         if(DCMP (d-radius[i]) <=0)return false;//the key to this problem $     } the     return true; the } the  the intMainvoid) - { in     //freopen ("10969in.txt", "R", stdin); the     intT; thescanf"%d", &T); About      while(t--) the     { thescanf"%d", &n); the          for(inti =0; I < n; ++i) scanf ("%LF%LF%LF", &radius[i], &p[i].x, &p[i].y); +          -         Doublesum =0.0; the          for(inti =0; I < n; ++i)Bayi         { thevector<Double>Rad; theRad.push_back (0.0); - Rad.push_back (TWO_PI); -              for(intj =0; J < N; ++j) the             { the                 if(j = = i)Continue; the getccintersection (P[i], radius[i], p[j], radius[j], RAD); the             } - sort (Rad.begin (), Rad.end ()); the              the              for(intj =0; J < Rad.size ()-1; ++j) the             {94                 DoubleMID = (Rad[j] + rad[j +1]) /2; the                 DoubleAng = Rad[j +1] -Rad[j]; thePoint C (p[i].x + Radius[i]*cos (mid), P[i].y + radius[i]*sin (mid)); the                 if(IsVisible (C, i)) sum + = radius[i] *ang;98             } About         } - 101printf"%.3f\n", sum);102     }103 104     return 0; the}
code June

UVa 10969 (cover problem between circle and round) Sweet Dream

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.