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