"Bzoj" 1043: [HAOI2008] Falling disk (computational geometry + greed)

Source: Internet
Author: User
Tags acos

http://www.lydsy.com/JudgeOnline/problem.php?id=1043

The only thing that I don't want is how to find the circumference of the circle and Qaaq ...

and find the Good God! We can turn the arc into $[0, 2 \pi]$ line!

Then be sure to pay attention! Starting point is $ (1, 0) $ (unit circle)

First I learned the cosine theorem ...

In the triangle ABC

$ $cos a=\frac{| ab|^2+| ac|^2-| bc|^2}{2| ab| | ac|} $$

Proving very simple ...

$$
\begin{align}
| {Bc}|^2 & = \VEC{BC} \cdot \VEC{BC} \ \
& = (\vec{ac}-\vec{ab}) \cdot (\vec{ac}-\vec{ab}) \ \
& = | \VEC{AC} |^2 + | \VEC{AB} |^2-2| ac| | Ab|cos A \ \
\end{align}
$$
The move is:
$ $cos a=\frac{| ab|^2+| ac|^2-| bc|^2}{2| ab| | ac|} $$

At the beginning of the puzzle, I thought about it and wrote it, seeking the intersection of the circle. The polar angle of the intersection ... Then discrete to the $[0, \pi]$ line ... Then loved the tragedy ...

You must know! The polar angle is calculated! But there may be two kinds of angles in the same position .... That's why I was so ${\alpha + 2k \pi}$ ....

So make a distinction. When the angle <0, first add $2\pi$, and then if the original angle is smaller than the size of the original corner is larger, it is divided into two paragraphs to calculate, namely $[0, r]$, $[l, 2\pi]$

Then sort the line with greedy.

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline const int Getint () {int r=0, k=1; Char c=g Etchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const double Pi=acos ( -1), Eps=1e-6;int dcmp (double x) {return ABS (x) <eps?0: (x<0?-1:1); }struct IPT {double x, y; IPT (double _x=0, double _y=0): X (_x), Y (_y) {}};struct Icir {IPT x; double r;}; typedef IPT IVT;IVT operator-(IPT &a, IPT &b) {return ivt (a.x-b.x, a.y-b.y);} Double Iangle (ivt v) {return atan2 (v.y, v.x);} Double Sqr (double x) {return x*x;} Double dis (IPT &a, IPT &b) {return sqrt (SQR (a.x-b.x) +SQR (A.Y-B.Y));} BOOL GETCC (Icir &a, Icir &b, double &ang1, double &ang2) {static Double D, Ang;d=dis (a.x, b.x); if (dcmp (d) = =0) return false;if (dcmp (a.r+b.r-d) <=0) return false;if (dcmp (a.r-b.r-d) >=0) return False;ang=iangle (b.x-a.x); Double Da=acos ((Sqr (d) +sqr (A.R)-SQR (B.R))/A.R/D/2); DBG (DA); Ang2=ang+da;return true;} const int N=1005;int n;icir a[n];struct dat {double L, R;} Line[n*2];bool cmp (const dat &a, const dat &b) {return a.l==b.l?a.r>b.r:a.l<b.l;} Double work (int now) {int ln=0;static double ang1, Ang2;for1 (i, now+1, n) {double D=dis (a[now].x, a[i].x); if (DCMP (a[i].r-a[now].r-d) >=0) return 0; }//puts ("here"); For1 (i, now+1, n) {if (GETCC (A[now], a[i], ang1, ang2) ==false) continue;if (ang1<0) ang1+=pi*2;if ( ang2<0) ang2+=pi*2;if (dcmp (ang1-ang2) >0) {++ln; line[ln].l=0; line[ln].r=ang2;++ln; line[ln].l=ang1; Line[ln]. r=pi*2;} else {++ln; line[ln].l=ang1; line[ln].r=ang2;}} Sort (line+1, LINE+1+LN, CMP);d ouble w=0, Mx=0;for1 (i, 1, LN) {if (dcmp (MX-LINE[I].R) >=0) Continue;mx=max (MX, line[i]. l); W+=line[i].r-mx;mx=max (MX, LINE[I].R);} Return a[now].r* (PI*2-W);} int main () {read (n); For1 (i, 1, N) scanf ("%lf%lf%lf", &AMP;A[I].R, &a[i].x.x, &a[i].x.y);d ouble Ans=0;for1 (i, 1, n ) ans+=work (i);p rintf ("%.3f\n", ans); return 0;}

  

Description

There are n discs falling from the sky, and the back can cover the front. The perimeter of the closed area that is finally formed. Look at this picture below, the total length of all red lines is the desired.

Input

N ri Xi y1 ... rn xn yn

Output

Last perimeter, reserved for three decimal places

Sample Input2
1 0 0
1 1 0Sample Output10.472hint

Data size

n<=1000

Source

"Bzoj" 1043: [HAOI2008] Falling disk (computational geometry + greed)

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.