LA 4064 (counting polar angles sort) Magnetic Train Tracks

Source: Internet
Author: User

This question is similar to UVa11529.

Enumerates a central point and then sorts it by a polar angle, counting the number of triangles that are obtuse at this point, and subtracting the answer with C (n, 3).

In addition encounter right triangle situation is very egg pain, can use an EPS, not too troublesome words to use integer vector do dot product.

1#include <cstdio>2#include <cmath>3#include <algorithm>4 using namespacestd;5 6typedefLong LongLL;7 Const intMAXN = -+Ten;8 Const DoublePI = ACOs (-1.0);9 Const DoubleEPS = 1e-9;Ten  One struct Point A { -     Doublex, y; - Point () {} thePoint (DoubleXDoubley): x (x), Y (y) {} - }P[MAXN], P2[MAXN]; -  -Pointoperator- (Constpoint& A,Constpoint&B) + { -     returnPoint (a.x-b.x, a.y-b.y); + } A  at DoubleANG[MAXN *2]; -  -LL-Inline C3 (intN) {return(LL) n * (n1) /2* (n2) /3; } -  - intMain () - { in     //freopen ("In.txt", "R", stdin); -     intN, Kase =0; to  +      while(SCANF ("%d", &n) = =1&&N) -     { the          for(inti =0; I < n; i++) scanf ("%LF%LF", &p[i].x, &p[i].y); *  $LL cnt =0;Panax Notoginseng          for(inti =0; I < n; i++) -         { the             intK =0; +              for(intj =0; J < N; J + +)if(J! =i) A             { theP2[K] = p[j]-P[i]; +ANG[K] =atan2 (P2[K].Y, p2[k].x); -Ang[k + N-1] = Ang[k] + PI *2.0; $k++; $             } -K =2*n-2; -Sort (ang, Ang +k); the             intL, R1 =0, R2 =0; -              for(L =0; L < n1; l++)Wuyi             { the                 DoubleB1 = ang[l] + PI/2; -                 DoubleB2 = Ang[l] +PI; Wu                  while(Ang[r1] <= b1-eps) r1++; -                  while(ANG[R2] < B2) r2++; AboutCNT + = R2-R1; $             } -         } -LL ans = C3 (n)-CNT; -printf"Scenario%d:\nthere is%lld sites for making valid tracks\n", ++Kase, ans); A     } +  the     return 0; -}
code June

LA 4064 (counting polar angles sort) Magnetic Train Tracks

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.