The sum of the areas of all triangles that can be composed of the points on a given plane
First we enumerate each point to establish a planar Cartesian coordinate with this point as the origin and then sort the points on the first to fourth quadrant and the X, Y axis positive half axes according to the slope.
Enumerating the second and third points to do this is an O (n^3) positive timeout But what did we find?
For each point K its contribution to the answer is:
(X1*YK-Y1*XK) + (X2*YK-Y2*XK) +...+ (X_ (k-1) *yk-y_ (k-1) *xk)
= (X1+x2+...+x_ (k-1)) *yk-(Y1+y2+...+y_ (k-1)) *xk
So just maintain a prefix and you can
Time complexity O (N^2LOGN)
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 3030using namespace std;struct point{int x, y; Double slope; Point () {} point (int _,int __): X (_), Y (__) {slope=x? ( Double) Y/x:1e10; } BOOL operator < (const point &y) const {if (x!=y.x) return x < y.x; Return y < y.y; }}a[m],points[m];int N,tot;long Long Ans;bool Compare (const point &p1,const point &p2) {return P1.slope < P2 . Slope;} int main () {int i,j; cin>>n; for (i=1;i<=n;i++) scanf ("%d%d", &a[i].x,&a[i].y); Sort (a+1,a+n+1); for (i=1;i<=n;i++) {tot=0; Long Long sum_x=0,sum_y=0; for (j=i+1;j<=n;j++) points[++tot]=point (A[J].X-A[I].X,A[J].Y-A[I].Y); Sort (points+1,points+tot+1,compare); for (j=1;j<=tot;j++) {ans+=sum_x*points[j].y-sum_y*points[j].x; sum_x+=points[j].x; SUM_Y+=POINTS[J].Y; }} printf ("%lld.%d\n", ans>>1,ans&1?5:0);}
Bzoj 1132 POI2008 Tro Computational geometry