Topic Link: UVA 11529-strange tax calculation
The main topic: give a number of points, to ensure that the random three points not collinear. Randomly select three points as triangle lines, and other points within the triangle, it is the inner point of the triangle. Ask how many internal points each triangle has on average.
How to solve the problem: the total number of triangles is very easyC ( 3 n ) , now is the total number of points required for each triangle interior. The same we can, in turn, ask for each point within the number of triangles.
Then we determine a point and ask how many triangles the point is inside. The remaining n-1 points. Can composeC ( 3n? 1 ])Triangle, so just ask for that point to be outside of which triangles.
The red point is the selected point, and the surrounding points are sorted according to the polar angle of the selected point, one at a time, and its polar angle is a. Points with all Poles less than A+PI. These points are made up of triangles. The selected point must be outside. The way to process a week is to expand the array of points by twice times, adding the polar angle of all points plus the PI to the extended array.
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace STD;Const intN =1205;Const DoublePI =4*Atan(1.0);Const DoubleEPS =1e-9;intNDoubleS, r[2*n];structPoint {Doublex, y;} P[n];DoubleCount (intD) {intc =0, MV =0; for(inti =0; I < n; i++) {if(i = = d)Continue;DoubleA =atan2(P[i].y-p[d].y, p[i].x-p[d].x); R[C] = A; r[c+n-1] = a +2*pi; C + +; } C =2N2; Sort (R, R + C);DoubleAns =0; for(inti =0; I < n1; i++) {DoubleTMP = R[i] + pi; while(tmp > R[MV]) mv++;DoubleCNT = mv-i-1; Ans = ans + cnt * (cnt-1) /2; }returnS-ans;}DoubleSolve () {s = (n1) * (n2) * (n3) /6.0;Doublec = n * (n1) * (n2) /6.0;DoubleAns =0; for(inti =0; I < n; i++) ans + = Count (i);returnANS/C;}intMain () {intCAS =1; while(scanf("%d", &n) = =1&& N) { for(inti =0; I < n; i++)scanf("%LF%LF", &p[i].x, &P[I].Y);printf("City%d:%.2lf\n", cas++, Solve ()); }return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
UVA 11529-strange Tax calculation (counting problem)